Super-newbie needs help!

Richard Chamberlain richardSPAM at geotek.co.uk
Thu Nov 29 11:06:37 CET 2001


"Daniel Klein" <danielk at aracnet.com> wrote in message
news:688b0ugij04trlh2aufriqil00nklvje80 at 4ax.com...
> Without looking at any of the responses so far, this is what I've come
> up with...
>
> while 1:
>         try:
>                 sum = int(raw_input("Enter your number: "))
>         except ValueError:
>                 print "You did not enter a number!"
>         else:
>                 if sum < 100:
>                         print "You haven't reached 100 yet!
>                         continue
>                 else:
>                         break
>
> Hope this helps,
> Daniel Klein

except you missed out the actually summing.

sum=0
 while 1:
         try:
                 sum+=int(raw_input("Enter your number: "))    # or
sum=sum+int(raw_input("Enter your number: "))
         except ValueError:
                 print "You did not enter a number!"
         else:
                 if sum < 100:
                         print "You haven't reached 100 yet!"
                         continue
                 else:
                         break

Richard







More information about the Python-list mailing list