Using Loops to track user input
Egor Bolonev
ebolonev at rol.ru
Sun Jul 6 18:17:57 EDT 2003
Hello, hokiegal99!
You wrote on Sun, 06 Jul 2003 16:32:37 -0400:
h> I don't understand how to use a loop to keep track of user input. Could
h> someone show me how to do what the program below does with a loop?
h> Thnaks!
h> ----------------------------
h> #Write a program that reads 10 numbers from the user and prints out the
h> sum of those numbers.
h> num0 = input("Enter a number: ")
h> num1 = input("Enter a number: ")
h> num2 = input("Enter a number: ")
h> num3 = input("Enter a number: ")
h> num4 = input("Enter a number: ")
h> num5 = input("Enter a number: ")
h> num6 = input("Enter a number: ")
h> num7 = input("Enter a number: ")
h> num8 = input("Enter a number: ")
h> num9 = input("Enter a number: ")
h> num = num0+num1+num2+num3+num4+num5+num6+num7+num8+num9
h> print num
h> ----------------------------------
=========Beginning of the citation==============
num = 0
for i in xrange(10):
num=num+input("Enter a number: ")
print num
=========The end of the citation================
With best regards, Egor Bolonev. E-mail: ebolonev at rol.ru [ru eo en]
More information about the Python-list
mailing list