problems with looping, i suppose

John Salerno johnjsal at NOSPAMgmail.com
Mon Mar 27 14:03:28 EST 2006


John Salerno wrote:
> Here's an exercise I was doing to guess a number from 1-100. 

Here's another question that is related:

while True:
     year = raw_input('Enter year (or other character to quit): ')

     try:
     	year = int(year)
     except NameError:
     	break

     if (year % 4 == 0) and (year % 100 != 0 or year % 400 == 0):
     	print year, 'is a leap year.\n'
     else:
     	print year, 'is not a leap year.\n'

raw_input()

This works as expected, except that if you enter any character other 
than a number, the program just quits. Why doesn't it still execute the 
raw_input function and pause? I think this is what is happening in the 
other exercise too, but I don't know why. If you break out of the loop, 
should it still pause at raw_input?



More information about the Python-list mailing list