Evening Community!

Alright. As you can see I am "newbie" on the block. When I try approaching my professor for assistance she tells me to go to my book. But I digress. If I was able to use a while loop this would be more simplified. But our professor is asking us to use a FOR loop and we have to use 2 functions.

Alright, easy enough. but WAIT, theres more. So below is my code but unfortunately I am getting back the awful "
TypeError: 'module' object is not iterable

I am sure it is something I completely overlooking but any step in the right direction would be awesome. Thanks!

Per instruction:

``````# get_values -  takes one argument (a number) that indicates the length
# of a list,gets the user input for a list of numbers,
# and returns the list of numbers. Use a for loop.

# do_analysis – takes one argument that is a list of numbers,
# then calculates and displays the statistical data specified
# by the problem. Hint: you may find built-in functions useful.

import numbers

def main ():
# create empty list
intro()
numbers = get_values()
get_values()
do_analysis()
input("press enter to continue.") # required

def intro ():
# explanation of program
print ("This program will get 20 numbers from you.")
print ("Once all numbers have been entered the program")
print ("will then analyze the data and display lowest number,")
print ("highest number, total, and average.")
print ("Alright! Let's begin.")
print ("-------------------------------------------------------")

def get_values():
values =[]
# get numbers and add to list
for i in range(20):
value =(int(input("Enter a number " + str(i + 1) + ": ")))
values.append(value)
return values

def do_analysis ():
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))
``````

## Recommended Answers

can you convert input to int?

module numbers you import seems not to be iterable.

You have to pass the "numbers" list to do_analysis. Now it is using the "numbers" from the import numbers statement. This is not a complete solution but should get you started: passing parameters …

## All 10 Replies

can you convert input to int?

module numbers you import seems not to be iterable.

You have to pass the "numbers" list to do_analysis. Now it is using the "numbers" from the import numbers statement. This is not a complete solution but should get you started: passing parameters to a function

``````def main ():
# create empty list
intro()
numbers = get_values()
## get_values()         Huh!!
do_analysis(numbers)
input("press enter to continue.") # required
``````

I know I know. She specifically asked for TWO functions and she specifically asked for me to name them SPECIFICALLY. I know this could be done much easier but this was the assignment. :(

And thank you Woooee for picking up on that. Sometimes it can be the smallest thing...

Thanks for your help. I have resolved and it works!

Hey @booicu, I have been trying to do something similar and have come across that error as well? I was wondering how you figured it out? Thanks!

Heya @jallen111, what I realized I did wrong was I put the return (values) within the for loop so it wasn't returning. Did you do that as well?

``````wrong: returning in for loop:
for i in range(20):
value =(int(input("Enter a number " + str(i + 1) + ": ")))
values.append(value)
return values

Right; return outside for loop

for i in range(20):
value =(int(input("Enter a number " + str(i + 1) + ": ")))
values.append(value)
return values
``````

You have to pass the list to the function using it i.e.

``````numbers = get_values()
do_analysis(numbers)
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.