优化if、elif过多
字典的成员运算,是判断字典的key
思路:把函数的内存地址存到字典当中
def login():
pass
def scan():
pass
def transfer():
pass
def query():
pass
def recharge():
pass
def opt():
pass
opt = input("输入要调用的功能>>>")
if opt == "0":
break
elif opt =="1":
login()
elif opt == "2":
scan()
elif opt == "...":
pass
# 通过这种方式可以优化,if,elif,太多的情况
my_dict = {"1":login,"2":scan,"3":transfer,"4":query,"5":recharge}
while True:
opt = input("输入要调用的功能>>>")
for opt in my_dict:
my_dict[opt]() # 拿到函数的内存地址以后,括号调用函数