Reputation: 45
Im studying for a exam in python and I dont know what to do with this freaking question. Write a program in python that in a loop asks the user for a integer until the user prints out 0. After the user prints out 0 the program shall print out the mean value of this program.
Pardon my probably not so well written English.
Upvotes: 0
Views: 620
Reputation: 2884
Is this what you are looking for?
x = []
i = ''
while i != 0:
i = int(raw_input("Please enter an integer: "))
x.append(i)
sum = 0
for number in x:
sum = sum + int(number)
print float(sum/int(len(x)-1))
Upvotes: 0
Reputation: 91069
from __future__ import division
data = [int(i) for i in iter(raw_input, '0')]
print "mean:", sum(data) / len(data)
Upvotes: 5