其他分享
首页 > 其他分享> > 把func和tuple dict组合的一种登录界面

把func和tuple dict组合的一种登录界面

作者:互联网


def login():
print("开始登录功能")

def register():
print("开始注册功能")

def transfer():
print("开始转账功能")

def withdraw():
print("开始提现功能")

def check_blance():
print("开始查询余额功能")


func_dict = {
'0': ("退出", None),
'1': ("登录", login),
'2': ("注册", register),
'3': ("提现", withdraw),
'4': ("转账", transfer),
'5': ("查询余额", check_blance),
}

while True:
for i in func_dict:
print(i, ' ', func_dict[i][0])
choice = input("请输入功能编号:").strip()
if choice.isdigit() is not True:
print("必须按编号输入")
continue
if choice == "0": # 注意这个地方是写“0”,而不是0,要加引号是str,不是int
# 因为前面input输入的是str
print('退出使用,再见!')
break
if choice in func_dict:
func_dict[choice][1]()
else:
print('功能编号选择的不对,请重新输入')

标签:功能,tuple,choice,dict,func,print,def
来源: https://www.cnblogs.com/leeyong49/p/16673746.html