Everything is working except when the user types N to end the while loop, it doesn't go to the For Statement (this happens when you run the program, works fine in the shell and in the py).
potato = []
count = 0
avg = 0
question = input('Finding averages, continue? Y or N: ')
while question == 'Y' and count <= 12:
num = int(input('Enter a number: '))
potato.append(num)
count += 1
question = input('Continue? Y or N: ')
for fries in potato:
avg = sum(potato)/count
print(fries,fries-avg)
print('average is: ' + str(avg))
#!/usr/bin/python
my_list=[]
val=int
sum1=int
n=int(input('Enter the limit:'))
for i in range(0,n):
val=int(input('number:'))
my_list.append(val)
sum1=sum(my_list)
print sum1
res=float(sum1/n)
print 'The average is:',res
It was breaking for me until I changed the input to raw_input. Now it exits the while loop when input is not Y:
question = raw_input('Finding averages, continue? Y or N: ')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.