[Tutor] while and for

Marcel Preda marcel@punto.it
Mon, 9 Oct 2000 19:58:31 +0200 (CEST)


On Mon, 9 Oct 2000 CMNOLEN@aol.com wrote:

> I asked earlier for guidance in writing a program to total input from 100 
> entries. It  worked great. Now I want the program to contain an 'Enter 0 to 
> quit' line. Also I would like a running count of the entries to show in the 
> 'The sum is now' line. I am stuck. I guess these questions are so basic most 
> print doesn't answer them?I am stuck! 
> 
> I am using:
> #########################################################
> total = 0
> for  i in range(100):
>     total = total + input("Please enter your next number: ")
>     print "The sum is now", total
> #########################################################


have to use `raw_input' function,
after  convert to int 

>>> for i in range(100):
...     new=raw_input("Enter the new value (0 to quit):")
...     if new=='0':
...             break 
...     total=total + int(new)
... 
Enter the new value (0 to quit):1
Enter the new value (0 to quit):3
Enter the new value (0 to quit):6
Enter the new value (0 to quit):7
Enter the new value (0 to quit):0
>>> total
17


PM