The second while loop doesn't exit even when the condition, both functions being true, is satisfied.
The second loop is similar to the first one which works fine so I'm not entirely sure what to do.
def access(self):
print("Please enter your 5 digit account number:")
self.accountNumber = input()
while Customer.valueCheck(self.accountNumber) or Customer.accountNumberCheck(self.accountNumber) == False:
if Customer.valueCheck(self.accountNumber) == False:
print("The account number must be 5 digits only.")
elif Customer.accountNumberCheck(self.accountNumber) == False:
print("The account number given does not match the any on file.")
print("Please try again:")
self.accountNumber = input()
print("Please enter your account name:")
self.name = input()
while Customer.nameCheck(self.name) or Customer.accountHolderCheck(self.accountNumber, self.name) == False:
if Customer.nameCheck(self.name) == False:
print("The name must contain alphabetic characters only.")
elif Customer.accountHolderCheck(self.accountNumber, self.name) == False:
print("The name given does not match the name paired with that account number.")
print("Please try again:")
self.name = input()
print("")
return (self.name, self.accountNumber)
def accountHolderCheck(accountNumber, name):
with open("bank_data.txt", "r") as searchData:
for line in searchData:
line.strip().split("\n")
if line.startswith(accountNumber):
bank_search = line.strip().split(",")
if bank_search[1] == name:
break
else:
return False
When the correct value is entered it asks to try again without saying any of the print statements, implying they're both true, but if both are true then surely the loop shouldn't run?
You need to put parenthesis around your two conditions. At the moment you are checking two different conditions:
Customer.valueCheck(self.accountNumber)
and
Customer.accountNumberCheck(self.accountNumber) == False
In other words, the first condition is checking whether that first part is true, not false. So if both are true, the loop will run because the first condition is met, but neither will come up as false so your last print statement
print("Please try again:")
will be triggered.
Instead, use:
while (Customer.valueCheck(self.accountNumber) and Customer.accountNumberCheck(self.accountNumber)) == False:
...
This will check whether either condition is false, and will not run if both are true.