当我尝试给它一个特定的错误时,除了函数总是被执行

Except function is always executed when I try and give it a specific error

我希望这个程序做的是只去每个,除非出现特定错误。现在它总是会进入 TypeError 异常并且会循环询问请给我你的号码,即使我已经输入了一些东西。

numb1 = input('Give me a number')

def error(numb1):
    try:
        numb1 >= 0
        print('Your wait time is', 45 / numb1)
    except TypeError:
        numb1 = input('Please give a number')
        return error(numb1)
    except ZeroDivisionError:
        numb1 = input('Do not use zero for your answer. Please input a new number:') 

error(numb1)

这正是我认为您正在尝试的。请注意,我使用循环而不是递归。成功就跳出循环

def error(numb1):
    while True:
        try:
            numb1 = int(input('Give me a number'))
            print('Your wait time is', 45 / numb1)
            break
        except TypeError:
            print( "That's not a number." )
        except ZeroDivisionError:
            print('Do not use zero for your answer.') 

error(numb1)