用python寫一個簡單的登錄


#coding=utf-8

'''
需求:要求注冊賬戶,然后注冊的賬戶登錄到系統后,顯示出登錄的昵稱
1.注冊的函數
2.登錄的函數
3.獲取昵稱的函數
'''

def Inout():
username = input('username:\n')
password = input('password please:\n')
return username,password

def register():
username, password = Inout()
temp=username+'|'+password
with open('login.md','w') as f:
f.write(temp)

def login():
'''登錄函數'''
username,password=Inout()
with open('login.md','r') as f:
info=f.read()
info=info.split('|')
if username==info[0] and password==info[1]:
return True
else:
return False

def getNick(func):
'''獲取昵稱'''
with open('login.md','r') as f:
info=f.read()
info=info.split('|')
if func:
print('{0}您好,歡迎您登錄'.format(info[0]))
else:
print('請登錄')

# if __name__=='__main__':
def main():
while True:
try:
t=input('1.注冊 2.登錄 3.退出系統\n')
#如果是float類型的處理
if isinstance(t,float):
t=int(t)
elif isinstance(t,str):
#判斷字符串是否大於1位,如果是,取出第一位,並把字母轉為數字
if len(t)==1:
t=ord(t)
else:
t=int(ord(list(t)[0]))
except Exception as e:
print(e.args)
else:
if t==1:
register()
elif t==2:
getNick(login())
elif t==3:
import sys
sys.exit()
else:
print('請注冊!')
finally:
pass
main()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM