try / except not worknig correctly

Robert Kern rkern at ucsd.edu
Sat Mar 12 19:44:05 EST 2005


'@'.join([..join(['fred','dixon']),..join(['gmail','com'])]) wrote:
> the code below will not execute the except section when i enter a
> number.
> what am i missing ?

Something that will actually raise ValueError.

It looks like you could use the help of the Python Tutor mailing list.

   http://www.python.org/mailman/listinfo/tutor

> #########################################
> .while 1:
> .   print 'Pump Protection ? '
> .   #line 133
> .    try:
> .        myInput = raw_input('A B C D E F G H I J K L ? ')
> .        myInput = string.upper(myInput)
> .        if myInput == 'A':break     #
> .        if myInput == 'B':break     #
> .        if myInput == 'C':break     #
> .        if myInput == 'D':break     #
> .        if myInput == 'E':break     #
> .        if myInput == 'F':break     #
> .        if myInput == 'G':break     #
> .        if myInput == 'H':break     #
> .        if myInput == 'I':break     #
> .        if myInput == 'J':break     #
> .        if myInput == 'K':break     #
> .        if myInput == 'L':break     #
> .    except ValueError:
> .         print "Oops! That was no valid number.  Try again..."
> .         pass
> 
> 
> .'s are to preserve indents.
> fred

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter



More information about the Python-list mailing list