Reputation: 119
I have hit rough spot in trying to figure out a problem that I am having with my code. I would like the output to result in:
Enter the high integer for the range 100
Enter the low integer for the range 20
Enter the integer for the multiples 15
List was created
The list has 5 elements.
90 75 60 45 30
Average of multiples is 60.00
I can figure out the "The list was created" part ....but the where it says "The list has 5 elements." on my code it keeps returning 30 instead 5. I was wondering if someone may point me into the right direction or portion to return the correct value. I greatly appreciate your help in this matter.
def main():
x = int(input('Enter the high integer for the range: '))
y = int(input('Enter the low integer for the range: '))
z = int(input('Enter the integer for the multiples: '))
mylist = show_multiples(x,y,z)
show_multiples(x,y,z)
show_list(mylist)
def show_multiples(x,y,z):
mylist = []
for num in range(x,y,-1):
if num % z == 0:
mylist.append(num)
return mylist
print ('List was created')
def show_list(mylist):
total = 0
for value in mylist:
total += value
average = total / len(mylist)
print ('The list has', value, 'elements.')
print (mylist,end=' ')
print ()
print ('Average of multiples is', format(average, '.2f'))
main()
Upvotes: 0
Views: 175
Reputation: 309821
It looks like you're just printing the wrong value:
print ('The list has', value, 'elements.')
should be:
print ('The list has', len(mylist), 'elements.')
Upvotes: 1