|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
创建的一个登陆程序:
代码如下
dict1={}
def xinjian():
ID=input('请输入用户名:')
while (ID in dict1.keys()):
ID=input('此用户已被使用,请重新输入:')
code=input('请输入密码:')
dict1[ID]=code
print('注册成功,赶紧试试登录吧')
def denglu():
name=input('请输入用户名')
while (name not in dict1.keys()):
name=input('您输入的用户名不存在,请重新输入:')
sec=input('请输入密码')
times=3
while sec != dict1[name]:
sec=input('您输入的密码不正确,请重新输入:')
times=times-1
if times ==0:
print('输入错误过多,无法进入')
break
if times>0:
print('欢迎进入系统')
else:
print('byebye')
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 == 'n' or choice == 'N':
xinjian()
elif choice == 'e' or choice == 'E':
denglu()
elif choice == 'q' or choice == 'Q':
break #退出死循环程序
showmenu()
为什么运行显示的时候会多一个引号,如下:
===================== RESTART: E:/python_code/用户登录程序.py =====================
'
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 退出程序:Q/q ---|
|--- 请输入指令代码:n
请输入用户名:小甲鱼
请输入密码:fishc
注册成功,赶紧试试登录吧
'
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 退出程序:Q/q ---|
|--- 请输入指令代码:e
请输入用户名小鲫鱼
您输入的用户名不存在,请重新输入:小甲鱼
请输入密码si
您输入的密码不正确,请重新输入:fush
您输入的密码不正确,请重新输入:fish
您输入的密码不正确,请重新输入:dasda
输入错误过多,无法进入
byebye
'
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 退出程序:Q/q ---|
|--- 请输入指令代码:e
请输入用户名小甲鱼
请输入密码fishc
欢迎进入系统
'
|--- 新建用户:N/n ---|
|--- 登录账号:E/e ---|
|--- 退出程序:Q/q ---|
|--- 请输入指令代码:
|
|