Andreas Restrup
Andreas Restrup

Reputation: 45

Write a program in python that in a loop asks the user for a integer until the user prints out 0

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

Answers (3)

mattjegan
mattjegan

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

glglgl
glglgl

Reputation: 91069

from __future__ import division
data = [int(i) for i in iter(raw_input, '0')]
print "mean:", sum(data) / len(data)

Upvotes: 5

Carlos
Carlos

Reputation: 1935

Your best bet is to really read through Python.org's WIKI. It's a great source of information and this link will surely get you on your way.

Upvotes: 2

Related Questions