I am working on a python project in which I use a while loop. Unique stuff. However, I can't get the loop to do its job for me.
My code:
with open("accounts.txt", "r") as account_file:
    while account == "":
        account = str(input("Enter a username: ") + " ")
        if account not in account_file.read():
            print("That username was not found.")
            account = ""
When I run this, it will prompt me to enter a username and if the string I entered (plus an added space) can be found in accounts.txt I will be told that my username can be found.
If I enter an invalid username, the program is supposed to tell me that it couldn't find the username I entered and then let me try again - except if I enter the username correctly on the next try, the program still tells me my username can't be found.
I tried making this change:
if account in account_file.read():
    account = account
else:
    print("That username was not found.")
    account = ""
And it still wouldn't work properly.
Can anyone tell me why?
I'm just looking for a simple solution.
 
    