problems with looping, i suppose

John Salerno johnjsal at
Mon Mar 27 21:03:28 CEST 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): ')

     	year = int(year)
     except NameError:

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


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