[Tutor] stuck on null values

Alan Gauld alan.gauld at btinternet.com
Fri Mar 16 20:02:23 CET 2012

On 16/03/12 14:44, Joel Goldstick wrote:

> Take a look at this:
> while True:
>    num = raw_input("give me an integer: ")
>    try:
>      n = int(num)
>      break
>    except:
>      print "Sorry, that wasn't and integer!"
>      pass

The pass is redundant it does nothing (thats its purpose! :-)
You can also remove the variable n:

while True:
        num = int(raw_input("give me an integer: "))
        # use num now or keep it for later
       print "Sorry, that wasn't an integer!"

# can also use num here...

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list