# Python Homework Help



## xXxALLANxXx

Number Analysis Program
Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in a list and then display the following data:
- The lowest number in the list
- The highest number in the list
- The Total of the numbers in the list
- The average of the numbers in the list

You must use a loop that loops 20 times and appends each score to a list after it is entered.

Code:



Code:


#
#This program will ask the user to enter a series of 20 numbers. It will then
#store the numbers in a list and then display the lowest number in the list,
#the highest, the total, and the average number in the list while using a loop.
#

def main():
    numbers = get_values()
    get_values()
    get_analysis(numbers)

def get_values():
    print('Please Enter A Series Of 20 Random Numbers')
    values =[]    
    for i in range(20):
        value =(int(input("Enter A Random Number " + str(i + 1) + ": ")))
        values.append(values)

    return values

def get_analysis (numbers):
    print("The Lowest Number Is: ") + str(min(numbers))
    print("The Highest Number Is: ") + str(max(numbers))
    print("The Sum The Numbers Is: ") + str(sum(numbers))
    print("The Average The Numbers Is:  ") + str(sum(numbers)/len(numbers))

main()


----------



## jvolkman

Is there something specific that you need help with?


----------



## tom.slick

Code:



Code:


def main():
    numbers = get_values()
    # get_values()   # not needed, you already called it 
    get_analysis(numbers)

def get_values():
    print('Please Enter A Series Of 20 Random Numbers')
    values =[]    
    for i in range(20):
        value =(int(input("Enter A Random Number " + str(i + 1) + ": ")))
        values.append(value)  # append value not values,  simple typo, but it makes a difference

    return values

def get_analysis (numbers):

    # your parentheses are in the wrong place http://docs.python.org/3.1/library/functions.html#print

    print("The Lowest Number Is:",  min(numbers))
    # print("The Lowest Number Is: ") + str(min(numbers))

    print("The Highest Number Is:", max(numbers))
    # print("The Highest Number Is: ") + str(max(numbers))

    print("The Sum The Numbers Is:", sum(numbers))
    # print("The Sum The Numbers Is:") + str(sum(numbers))

    print("The Average The Numbers Is:", sum(numbers)/len(numbers))
    # print("The Average The Numbers Is:  ") + str(sum(numbers)/len(numbers))

main()

assuming this is python 3


----------



## xXxALLANxXx

Oh sorry I forgot to post my error I was getting.

Code:



Code:


Traceback (most recent call last):
  File "F:/Python33/Beckett, Allan Assignment #9.py", line 30, in <module>
    main()
  File "F:/Python33/Beckett, Allan Assignment #9.py", line 13, in main
    get_analysis(numbers)
  File "F:/Python33/Beckett, Allan Assignment #9.py", line 25, in get_analysis
    print("The Lowest Number Is: ") + str(min(numbers))
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'


----------



## xXxALLANxXx

Quote:


> Originally Posted by *tom.slick*
> 
> Code:
> 
> 
> 
> Code:
> 
> 
> def main():
> numbers = get_values()
> # get_values()   # not needed, you already called it
> get_analysis(numbers)
> 
> def get_values():
> print('Please Enter A Series Of 20 Random Numbers')
> values =[]
> for i in range(20):
> value =(int(input("Enter A Random Number " + str(i + 1) + ": ")))
> values.append(value)  # append value not values,  simple typo, but it makes a difference
> 
> return values
> 
> def get_analysis (numbers):
> 
> # your parentheses are in the wrong place http://docs.python.org/3.1/library/functions.html#print
> 
> print("The Lowest Number Is:",  min(numbers))
> # print("The Lowest Number Is: ") + str(min(numbers))
> 
> print("The Highest Number Is:", max(numbers))
> # print("The Highest Number Is: ") + str(max(numbers))
> 
> print("The Sum The Numbers Is:", sum(numbers))
> # print("The Sum The Numbers Is:") + str(sum(numbers))
> 
> print("The Average The Numbers Is:", sum(numbers)/len(numbers))
> # print("The Average The Numbers Is:  ") + str(sum(numbers)/len(numbers))
> 
> main()
> 
> assuming this is python 3


Thanks for the help, my book was suggesting that str was to be used. Your code seemed to work and had no problems.
Thanks again,
ALLAN


----------



## jvolkman

In general, str.format is better to use when formatting strings. get_values can be rewritten using str.format:

Code:



Code:


def get_values():
    print('Please Enter A Series Of 20 Random Numbers')
    values =[]    
    for i in range(20):
        value = int(input("Enter A Random Number {}: ".format(i+1)))
        values.append(value)

    return values


----------



## tom.slick

Quote:


> Originally Posted by *xXxALLANxXx*
> 
> Thanks for the help, my book was suggesting that str was to be used. Your code seemed to work and had no problems.
> Thanks again,
> ALLAN


Yes you can use str to turn a int into a string, but again it comes back to the way you were doing it
notice the placement of the parentheses (extra space added to make the parentheses stand out)

wrong way

Code:



Code:


print ( "The Lowest Number Is: " ) + str ( min ( numbers ) )

in the above you have 2 seperate functions on the same line, print() and str(), both seperate.

correct way
the placement of parentheses makes a differents

Code:



Code:


print ( "The Lowest Number Is: " + str ( min ( numbers ) ) )

or

Code:



Code:


print ( ( "The Lowest Number Is: " ) + str ( min ( numbers ) ) )

the print function will print what is between the parentheses,


----------

