python如何实现不用装饰器实现登陆器小程序
更新时间:2019年12月14日 11:51:31 作者:Iceberg_710815
这篇文章主要介绍了python如何实现不用装饰器实现登陆器小程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
这篇文章主要介绍了python如何实现不用装饰器实现登陆器小程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
下面代码演示了不使用装饰器实现用户登陆功能的小程序,在python3.x下可正常运行
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 26 15:26:58 2019
@author: root
"""
def menu():
print('choice'.center(50,'-'))
msg = '''
1. home
2. finance
3. book
4. exit
'''
print(msg)
print("".center(50,'-'))
def login(login_flat,choice):
if not login_flat:
while True:
username = str(input("username:"))
password = str(input("password:"))
if choice == '1':
home()
with open('jingdong.txt','r') as f1:
for line in f1:
element = line.split(" ",1)
print(element[0])
print(element[1])
if username.strip() == element[0].strip() and password.strip() == element[1].strip():
print("log in successful!")
return True
print("failed to log in!,try it again!")
elif choice == '2':
finance()
with open('weixin.txt','r') as f2:
for line in f1:
element = line.split(" ",1)
if username.strip() == element[0].strip() and password.strip() == element[1].strip():
print("log in successful!")
return True
print("failed to log in!,try it again!")
elif choice == '3':
book()
with open('jingdong.txt','r') as f3:
for line in f3:
element = line.split(" ",1)
if username.strip() == element[0].strip() and password.strip() == element[1].strip():
print("log in successful!")
return True
print("failed to log in!,try it again!")
else:
print("You have logged in before!")
return True
#@login(login_flat,choice)
def home():
print("home.....")
#@login(login_flat,choice)
def finance():
print("finance.....")
#@login(login_flat,choice)
def book():
print("book.....")
login_flag = False
while True:
menu()
choice = input("your choice:")
if choice == '1':
login_flag = login(login_flag,choice)
elif choice == '2':
login_flag = login(login_flag,choice)
elif choice == '3':
login_flag = login(login_flag,choice)
elif choice == '4':
print('bye-bye')
break
else:
print("wrong input ,try it again!")
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Python中easy_install 和 pip 的安装及使用
本篇文章主要介绍了Python中easy_install 和 pip 的安装及使用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-06-06
python如何使用requests提交post请求并上传文件(multipart/form-data)
这篇文章主要给大家介绍了关于python如何使用requests提交post请求并上传文件(multipart/form-data)的相关资料,Python有许多库支持,它们可以简化HTTP上的数据传输,requests库是最受欢迎的Python包之一,因为它在网络刮削中被大量使用,需要的朋友可以参考下2023-11-11
jupyter 使用Pillow包显示图像时inline显示方式
这篇文章主要介绍了jupyter 使用Pillow包显示图像时inline显示方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-04-04
详解利用python+opencv识别图片中的圆形(霍夫变换)
这篇文章主要介绍了详解利用python+opencv识别图片中的圆形(霍夫变换),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2019-07-07
python使用beautifulsoup4爬取酷狗音乐代码实例
这篇文章主要介绍了python使用beautifulsoup4爬取酷狗音乐代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2019-12-12


最新评论