problems with looping, i suppose

Scott David Daniels scott.daniels at acm.org
Mon Mar 27 16:42:55 EST 2006


John Salerno wrote:
> 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
>     ...
> 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? 

Here's a clue:
        try:
            try:
                x = int('abc')
            except FloatingPointError:
                print 'never reached'
            print 'This is not reached either'
        except ValueError:
            print 'proper exception'
        raw_input('Pause and reflect:')

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list