Using Loops to track user input

Behrang Dadsetan ben at
Mon Jul 7 00:31:58 CEST 2003

Behrang Dadsetan wrote:
> hokiegal99 wrote:
>> I don't understand how to use a loop to keep track of user input. 
>> Could someone show me how to do what the program below does with a loop?
> # If you are want to loop a fixed amount of time, as I understand a way
> # would be:
> sum = 0
> for i in xrange(10):
>    sum += input("Enter a number: ")
> average = sum/10
> print average

Ok, I just looked up the Reference documentation and 
int(raw_input("prompt text")) would be probably better than my suggested 
input() - like in the other anwsers you received.

One should maybe note that if the end average calculated should be a 
float, then you need to use

sum = 0.0

and should the user entering the data be allowed to use float values you 
will probably want to use

float(raw_input("prompt text"))

Regards, Ben.

More information about the Python-list mailing list