|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
答案是这样的:
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)
if passwd == pwd:
print('欢迎进入XXOO系统,请点右上角的X结束程序!')
else:
print('密码错误!')
def showmenu():
prompt = '''
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 推出程序:Q/q ---|
|--- 请输入指令代码:'''
while True:
chosen = False
while not chosen:
choice = input(prompt)
if choice not in 'NnEeQq':
print('您输入的指令代码错误,请重新输入:')
else:
chosen = True
if choice == 'q' or choice == 'Q':
break
if choice == 'n' or choice == 'N':
new_user()
if choice == 'e' or choice == 'E':
old_user()
showmenu()
我想在源代码的基础上能够再添加两个功能。(1)代码输入错误时可以直接在后面重新输入,|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 推出程序:Q/q ---|
|--- 请输入指令代码:'''而不是又打出这一段。(2)old_user密码输入错误之后可以有重新输入密码的机会
求问各位大佬如何添加?
2、求问各位大佬,为什么每次循环都会打出 '''
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 推出程序:Q/q ---|
|--- 请输入指令代码:''',如果上次输入的指令为e/n,下次循环的时候choice的值不应该保存了n/e吗?为什么还是 '''
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 推出程序:Q/q ---|
|--- 请输入指令代码:'''???
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),不知道是不是这个意思
|
|