把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('功能编号选择的不对,请重新输入')

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288488.html

(0)
上一篇 2022年9月9日
下一篇 2022年9月9日

相关推荐

发表回复

登录后才能评论