Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does my code go through the first for loop but not the second for loop?

So to start this off, this is not the complete program. I am working on a bank management system and just ran into this problem. I’m trying to make the customer type in their login ID and password and it checks the first file after that the code will open another file that checks which the first element is the same as the login ID then print out customer account type and balance. The text file example is at the bottom and I have no idea why my code run through the first loop but not the second.

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|saving|1000|Lee|3088|00001|200

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think this is suffice if you do not modify the txt file:

G = open("system.txt", "r")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading