Beginner Programmer Question
Michael Goettsche
mail at tuxipuxi.org
Mon Jun 26 13:48:27 EDT 2006
kydavis77 at gmail.com wrote:
> I am doing alot of reading and trying to teach myself how to program.
> I can not figure out how to make "Write a program that continually
> reads in numbers from the user and adds them together until the sum
> reaches 100." this work. If someone could show me the correct code so i
> can learn from that it would be much appreciated. Thanks
>
sum = 0
while sum <= 100:
number = int(raw_input("Enter a number\n"))
sum = sum + number
print "Finally there"
As long as the sum is <= 100 the program asks for a number and adds it
to the sum variable. If the variable is >= 100, it exits and outputs the
string.
More information about the Python-list
mailing list