如何捕获空的击键或无效的int(input)输入

时间:2019-06-19 14:40:27

标签: python python-3.x

创建一个atm程序效果很好,但是我的问题是,如果用户按enter键或任何字母会使该程序崩溃。

如果选项!= int(输入,则尝试使用ord(),chr()。

if deposit_withdrawal_mode == False:
        option = int(input())
elif transfer_funds_mode == False:
        option = int(input())

if option == 6:
        pin_error = True
        print("Exited Program")
        break
    elif option < 1:
        print("***Invalid Entry***")
    elif option > 6:
        print("***Invalid Entry***")

expected output when user enters anything but an integer thats valid for 
the options: Invalid entry

Actual output: invalid literal for int() with base 10

0 个答案:

没有答案