所以,我有一個像本地登錄/注冊系統一樣的程式。它詢問用戶是否要注冊或登錄。如果他們注冊,他們應以某種格式輸入用戶名和密碼,并將其放入檔案中。
如果他們選擇登錄,程式將假定他們將要輸入的內容位于檔案中。預期用途是,如果它在檔案中,它會說該帳戶有效。如果用戶輸入的東西不在檔案中,它應該說它不是一個有效的帳戶。
到目前為止,輸出總是說該帳戶無效,即使它在檔案中。這是代碼的登錄部分:
elif sol == "l":
os.system("clear")
print("You have chosen to login.")
time.sleep(2)
os.system("clear")
datasearch = input("What is your username and password?(username/password): ")
with open ("user_database.txt", "r") as searchdata:
if datasearch in os.linesep:
os.system("clear")
print("This is a valid account!")
time.sleep(3)
os.system("clear")
quit()
else:
os.system("clear")
print("This is not a valid account!")
time.sleep(3)
os.system("clear")
uj5u.com熱心網友回復:
您不是在搜索檔案。您正在檢查用戶輸入是否在os.linesep.
你應該在你的代碼中放置類似if datasearch in searchdata.read():inplace of 的東西if datasearch in os.linesep:。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/341434.html
上一篇:pythonid()函式實作
