Chris that is the one I am currently stuck on. Ive tried putting the try block where I believe it should go but it doesnt work. For anyone that is looking at this thats knows python please enlighten me. Ive been pondering this for 3 days now! here is the bottom part where the try block will need to go
Code:
phone_list = {}
menu_choice = 0
print_menu()
while menu_choice != 7:
#here is where i am putting try:
menu_choice = input("Type in a number (1-7):")
if menu_choice == 1:
print_numbers(phone_list)
elif menu_choice == 2:
print "Add Name and Number"
name = raw_input("Name:")
phone = raw_input("Number:")
add_number(phone_list,name,phone)
elif menu_choice == 3:
print "Remove Name and Number"
name = raw_input("Name:")
remove_number(phone_list,name)
elif menu_choice == 4:
print "Lookup Number"
name = raw_input("Name:")
print lookup_number(phone_list,name)
elif menu_choice == 5:
filename = raw_input("Filename to load:")
load_numbers(phone_list,filename)
elif menu_choice == 6:
filename = raw_input("Filename to save:")
save_numbers(phone_list,filename)
elif menu_choice == 7:
pass
else:
print_menu()
print "Goodbye"
#here is where im putting valueError
and the code for the try block is
Code:
#this is the start of the try block for anyone who doesnt know
try:
#this is the end of the try block
except valueError
print "That was not a valid choice"
I keep wanting to put it right under the while statement and from the examples it gave that appears correct but then it still fails when anything but a number is entered. Please help
Bookmarks