try: except: ValueError

Mike Hoy mhoy4 at cox.net
Fri Jun 10 13:19:27 EDT 2005


hi

my goal is to handle the problem of a user typing a letter or symbol
rather than a number I found something called try: and ValueError:

Anyway this is what i attempted:

#menuloop
menuChoice = 7
printMenu()
while menuChoice != 0:
	try:
		menuChoice = int("1 = write | 2 = view | 0 = quit"))
	except ValueError:
		print "enter a number"

	if menuChoice == 1:
		writeEntry()
	elif menuChoice == 2:
		viewEntry()
	elife menuChoice == 0:
		pass
	else:
		printMenu()

print "bye"

this works as though I never added try: and except ValueError: at all.
the program just doesn't use them at all.

if a user types a&s it still errors 'a&s' is not defined

what am i doing wrong here?




More information about the Python-list mailing list