所以我正在為我的銀行管理專案嘗試一個登錄系統,我創建了兩個登錄系統。一個用于管理系統,另一個用于客戶。這是兩者的代碼和文本檔案。為什么我的第一個函式可以作業,而不是第二個?僅供參考,我不能使用任何全域函式和字典,我得到的錯誤是 ValueError: too many values to unpack (expected 2)
def LAdminAccount():
EnteredStaffAccountNumber = str(input("========== Please Type in Your Account Number:"))
EnteredStaffPassword = str(input("========== Please Type in Your Password:"))
A= open("AdminUser.txt","r")
for line in A.readlines():
us,pw = line.strip().split("|")
if (EnteredStaffAccountNumber == us ) and (EnteredStaffPassword == pw):
print ("Login successful")
A.close()
AdminMenu()
print ("Wrong username/password")
return
def LCustomerAccount():
EnteredID = str(input("========== Please Type in Your Account ID:"))
EnteredPassword = str(input("========== Please Type in Your Password:"))
B= open("Customerlogin.txt","r")
for line in B.readlines():
id,pw = line.split("|",1)
print (id)
print (pw)
if (EnteredID == id ) and (EnteredPassword == pw):
print ("Customer Login successful")
B.close()
CustomerMenu()
print ("Wrong Account Number/password")
menu()
管理員用戶名.txt
00001|1234
客戶登錄.txt
000403100865|3088
輸出是:
000403100865
3088
客戶登錄成功
錯誤的帳號/密碼
uj5u.com熱心網友回復:
該錯誤表明問題在于以下行:
id,pw = line.split("|")
如果您有多個“|” 在您的文本中,您將無法以這種方式拆分它們。
為了保證字串最多被拆分一次,請嘗試替換為:
id,pw = line.split("|", 1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/375391.html
