python如何实现不用装饰器实现登陆器小程序
这篇文章主要介绍了python如何实现不用装饰器实现登陆器小程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
下面代码演示了不使用装饰器实现用户登陆功能的小程序,在python3.x下可正常运行
#!/usr/bin/envpython3
#-*-coding:utf-8-*-
"""
CreatedonTueNov2615:26:582019
@author:root
"""
defmenu():
print('choice'.center(50,'-'))
msg='''
1.home
2.finance
3.book
4.exit
'''
print(msg)
print("".center(50,'-'))
deflogin(login_flat,choice):
ifnotlogin_flat:
whileTrue:
username=str(input("username:"))
password=str(input("password:"))
ifchoice=='1':
home()
withopen('jingdong.txt','r')asf1:
forlineinf1:
element=line.split("",1)
print(element[0])
print(element[1])
ifusername.strip()==element[0].strip()andpassword.strip()==element[1].strip():
print("loginsuccessful!")
returnTrue
print("failedtologin!,tryitagain!")
elifchoice=='2':
finance()
withopen('weixin.txt','r')asf2:
forlineinf1:
element=line.split("",1)
ifusername.strip()==element[0].strip()andpassword.strip()==element[1].strip():
print("loginsuccessful!")
returnTrue
print("failedtologin!,tryitagain!")
elifchoice=='3':
book()
withopen('jingdong.txt','r')asf3:
forlineinf3:
element=line.split("",1)
ifusername.strip()==element[0].strip()andpassword.strip()==element[1].strip():
print("loginsuccessful!")
returnTrue
print("failedtologin!,tryitagain!")
else:
print("Youhaveloggedinbefore!")
returnTrue
#@login(login_flat,choice)
defhome():
print("home.....")
#@login(login_flat,choice)
deffinance():
print("finance.....")
#@login(login_flat,choice)
defbook():
print("book.....")
login_flag=False
whileTrue:
menu()
choice=input("yourchoice:")
ifchoice=='1':
login_flag=login(login_flag,choice)
elifchoice=='2':
login_flag=login(login_flag,choice)
elifchoice=='3':
login_flag=login(login_flag,choice)
elifchoice=='4':
print('bye-bye')
break
else:
print("wronginput,tryitagain!")
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。