为什么我的代码通过第一个 for 循环而不是第二个 for 循环?
Why does my code go through the first for loop but not the second for loop?
所以开始吧,这不是完整的程序。我正在研究银行管理系统,只是 运行 遇到了这个问题。我试图让客户输入他们的登录 ID 和密码,然后它检查第一个文件,然后代码将打开另一个文件,检查第一个元素与登录 ID 相同,然后打印出客户帐户类型和余额.文本文件示例在底部,我不知道为什么我的代码 运行 通过第一个循环而不是第二个循环。
def LCustomerAccount():
EnteredID = str(input("========== Please Type in Your Account ID:"))
EnteredPassword = str(input("========== Please Type in Your Password:"))
B = open("Customerlogin.txt", "r")
G = open("system.txt", "a+")
Account_NumberList = []
for line in B.readlines():
id, pw = line.strip().split("|", 1)
if (EnteredID == id) and (EnteredPassword == pw):
print("========== Login Successfull============")
print("========== Welcome User============")
Account_NumberList.append(EnteredID)
B.close()
break
else:
print("Wrong Account Number/password")
menu()
for line in G.readlines():
idc,at,balance= line.strip().split("|",2)
if (idc == Account_NumberList):
print("Your Account Type:", at)
print("Your Account Balance:",balance)
print("========== (Option 1). Deposit an amount from your account ============")
print("========== (Option 2). Withdraw an amount from your account============")
print("========== (Option 3). Change Your Account Password ============")
print("========== (Option 4). Log Out ============")
EnterOption = int(input("==========Please Enter Your Option"))
Customerlogin.txt
020403100865|3088
System.txt
020403100865|节省|1000|李|3088|00001|200
如果你不想修改txt文件,我想这就足够了:
G = open("system.txt", "r")
所以开始吧,这不是完整的程序。我正在研究银行管理系统,只是 运行 遇到了这个问题。我试图让客户输入他们的登录 ID 和密码,然后它检查第一个文件,然后代码将打开另一个文件,检查第一个元素与登录 ID 相同,然后打印出客户帐户类型和余额.文本文件示例在底部,我不知道为什么我的代码 运行 通过第一个循环而不是第二个循环。
def LCustomerAccount():
EnteredID = str(input("========== Please Type in Your Account ID:"))
EnteredPassword = str(input("========== Please Type in Your Password:"))
B = open("Customerlogin.txt", "r")
G = open("system.txt", "a+")
Account_NumberList = []
for line in B.readlines():
id, pw = line.strip().split("|", 1)
if (EnteredID == id) and (EnteredPassword == pw):
print("========== Login Successfull============")
print("========== Welcome User============")
Account_NumberList.append(EnteredID)
B.close()
break
else:
print("Wrong Account Number/password")
menu()
for line in G.readlines():
idc,at,balance= line.strip().split("|",2)
if (idc == Account_NumberList):
print("Your Account Type:", at)
print("Your Account Balance:",balance)
print("========== (Option 1). Deposit an amount from your account ============")
print("========== (Option 2). Withdraw an amount from your account============")
print("========== (Option 3). Change Your Account Password ============")
print("========== (Option 4). Log Out ============")
EnterOption = int(input("==========Please Enter Your Option"))
Customerlogin.txt
020403100865|3088
System.txt
020403100865|节省|1000|李|3088|00001|200
如果你不想修改txt文件,我想这就足够了:
G = open("system.txt", "r")