python如何實(shí)現(xiàn)不用裝飾器實(shí)現(xiàn)登陸器小程序
這篇文章主要介紹了python如何實(shí)現(xiàn)不用裝飾器實(shí)現(xiàn)登陸器小程序,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
下面代碼演示了不使用裝飾器實(shí)現(xiàn)用戶登陸功能的小程序,在python3.x下可正常運(yùn)行
#!/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!")
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于Python批量鑲嵌拼接遙感影像/柵格數(shù)據(jù)(示例代碼)
這篇文章主要介紹了基于Python批量鑲嵌拼接遙感影像/柵格數(shù)據(jù),使用時(shí)直接修改Mosaic_GDAL函數(shù)的入?yún)⒕托辛?選擇數(shù)據(jù)存放的路徑會(huì)自動(dòng)拼接,命名也會(huì)自己設(shè)置無(wú)需額外修改,需要的朋友可以參考下2023-10-10
使用Python編寫Prometheus監(jiān)控的方法
今天小編就為大家分享一篇關(guān)于使用Python編寫Prometheus監(jiān)控的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-10-10
Python中easy_install 和 pip 的安裝及使用
本篇文章主要介紹了Python中easy_install 和 pip 的安裝及使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
python如何使用requests提交post請(qǐng)求并上傳文件(multipart/form-data)
這篇文章主要給大家介紹了關(guān)于python如何使用requests提交post請(qǐng)求并上傳文件(multipart/form-data)的相關(guān)資料,Python有許多庫(kù)支持,它們可以簡(jiǎn)化HTTP上的數(shù)據(jù)傳輸,requests庫(kù)是最受歡迎的Python包之一,因?yàn)樗诰W(wǎng)絡(luò)刮削中被大量使用,需要的朋友可以參考下2023-11-11
jupyter 使用Pillow包顯示圖像時(shí)inline顯示方式
這篇文章主要介紹了jupyter 使用Pillow包顯示圖像時(shí)inline顯示方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04
基于Python實(shí)現(xiàn)新年倒計(jì)時(shí)
眼看馬上春節(jié)就要來(lái)臨了,所以滿懷期待的寫了一個(gè)Python新年倒計(jì)時(shí)的小工具!文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-01-01
詳解利用python+opencv識(shí)別圖片中的圓形(霍夫變換)
這篇文章主要介紹了詳解利用python+opencv識(shí)別圖片中的圓形(霍夫變換),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
python使用beautifulsoup4爬取酷狗音樂代碼實(shí)例
這篇文章主要介紹了python使用beautifulsoup4爬取酷狗音樂代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12

