1.你看下是这样吗user_data = {}
def new_user():
prompt = '请输入用户名:'
while True:
name = input(prompt)
if name in user_data:
prompt = '此用户名已经被使用,请重新输入:'
continue
else:
break
passwd = input('请输入密码:')
user_data[name] = passwd
print('注册成功,赶紧试试登录吧^_^')
def old_user():
prompt = '请输入用户名:'
while True:
name = input(prompt)
if name not in user_data:
prompt = '您输入的用户名不存在,请重新输入:'
continue
else:
break
passwd = input('请输入密码:')
pwd = user_data.get(name)
vol = 2
while vol:
vol -= 1
if passwd == pwd:
print('欢迎进入XXOO系统,请点右上角的X结束程序!')
else:
if vol:
print('密码错误,请重新输入!')
passwd = input('请输入密码:')
else:
print('密码错误!')
def showmenu():
prompt = '''
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 推出程序:Q/q ---|
|--- 请输入指令代码:'''
while True:
chosen = False
while not chosen:
index = 2
choice = input(prompt)
while index:
if index:
if choice not in 'NnEeQq' and index == 2:
choice = input('您输入的指令代码错误,请重新输入:')
elif choice not in 'NnEeQq' and index == 1:
print('您输入的指令代码错误,请重新输入!')
else:
chosen = True
break
else:
break
index -= 1
if choice == 'q' or choice == 'Q':
break
if choice == 'n' or choice == 'N':
new_user()
if choice == 'e' or choice == 'E':
old_user()
showmenu()
2.因为它每次循环都有choice = input(prompt),不知道是不是这个意思 |