1. 程式人生 > >【python入門】簡單實現註冊、登陸、刪除賬戶

【python入門】簡單實現註冊、登陸、刪除賬戶

作為一個迷惘的金融狗,曾關注一些實習要求python,開始瞭解這門語言。

後來發現在金融這一領域的實習要求中,要求python而不是各種證書&實習經歷的僅僅是佔少數。

這條路,漫漫長而又艱險。一定會遇見光,但是很可能不是屬於金融背景的python程式設計師。也許是IT、數理背景出身的具備python程式設計能力的懂得基礎金融知識的人吧。

金融金融,當今也許皇冠不在,但是仍是不錯的選擇。

 

程式設計師之路

只求不脫髮&性別不歧視。

若是個男生倒不介意了

 

——————以下為主要內容——————

本次程式碼實現的是 註冊、登陸以及刪除賬戶的功能。

如果有更簡潔、高效的寫法,歡迎和我交流呀~
# Author:王帥帥的升級打怪之路
'''
登陸介面可實現功能:
註冊(可檢測是否重名);
登陸(輸錯三次鎖定);
登出賬戶(輸錯三次鎖定)。
可實現註冊後接著登陸或者登出賬戶。
'''

# 儲存使用者名稱和密碼的列表。
usernameANDpassword_list = [["mac", "abc123"], ["apple", "6789bnm"], ["pencil", "123456"]]

UserChoice = input("Enter register, login or delete.")
Judgement = True
while Judgement: if UserChoice == "register": flag1 = True while flag1: username = input("Register:input a username.") keyV = 0 # 用於判斷註冊輸入的使用者名稱是否已存在。 for i in usernameANDpassword_list: if username == i[0]: keyV
+= 1 else: keyV += 0 if keyV != 0: print("The name already exists, please try another one.") else: password = input("Register:input your password.") usernameANDpassword_list.append([username, password]) print("you've already registered.") flag1 = False # 註冊成功之後跳出while迴圈 Continue = input("Please input N to exist or Y to continue other operations.") if Continue == "N": Judgement = False else: UserChoice = input("Enter register, login or delete.") elif UserChoice == "login": count = 0 keyV = 0 while count < 3: username = input("Login:input your username.") password = input("Login:input your password.") for i in usernameANDpassword_list: if username == i[0] and password == i[1]: keyV += 1 else: keyV += 0 if keyV != 0: print("you've login!!!") Continue = input("Please input N to exist or Y to continue login or delete.") if Continue == "N": Judgement = False else: UserChoice = input("Enter register, login or delete.") break # 退出while迴圈 else: print("your username or password is wrong.") count += 1 if count == 3: print("you've tried too many times.Your account has been locked.") Judgement = False elif UserChoice == "delete": count = 0 keyV = 0 while count < 3: username = input("Delete:input your username.") password = input("Delete:input your password.") for i in usernameANDpassword_list: if username == i[0] and password == i[1]: keyV += 1 else: keyV += 0 if keyV != 0: delete_confirm = input("Are you sure? \ Please input Y to delete or N to cancel.") if delete_confirm == "Y": index = usernameANDpassword_list.index([username, password]) del usernameANDpassword_list[index] print("your account has been deleted.") Continue = input("Please input N to exist or Y to continue login or delete.") if Continue == "N": Judgement = False else: UserChoice = input("Enter register, login or delete.") break # usernameANDpassword_list.pop(index) 另一種刪除方法。 else: print("you cancel this operation.") Continue = input("Please input N to exist or Y to continue login or delete.") if Continue == "N": Judgement = False else: UserChoice = input("Enter register, login or delete.") break else: count += 1 if count == 3: print("you've tried too many times.") Continue = input("Please input N to exist or Y to continue login or delete.") if Continue == "N": Judgement = False else: UserChoice = input("Enter register, login or delete.") else: print("the username or password is wrong or unavailable.") else: print("you didn't correctly choose a function.") Judgement = False