使用ValueError()时的TypeError

时间:2014-05-20 02:18:39

标签: python typeerror

在下面的代码中,我收到以下错误:

except ValueError():
TypeError: catching classes that do not inherit from BaseException is not allowed

代码:

    numPizza = int(input("Enter the number of pizzas wanted (max 5)"))
    orderPizza = 0
    global order
    order = []
    total_cost = 0

    while orderPizza < numPizza:
        Order_Menu() 
        select_pizza = 0
        good_input = True
        while good_input:
            global selection
            selection = int(input("Enter your selection for pizza(s) 0-12: "))
            try:
                if selection < 0 or selection > 12:
                    print("Not a valid option restarting in 3 seconds")
                    time.sleep(3)
                    continue
            except ValueError():
                print("not a number")

1 个答案:

答案 0 :(得分:0)

除了

之外,取出那些parens
try:
   #do something
except ValueError:
   print "doh!"