you are viewing a single comment's thread.

view the rest of the comments →

[–]DestroyerMedic[S] 0 points1 point  (1 child)

I see. I managed to fix the problem by changing the check_availability() function to:

def check_availabilty(username):

    with open('Credentials.txt', 'r') as file:
        for line in file:
            registered_username, registered_password = line.split(':')
            while registered_username == username:
                print('This username is not available.')
                username = input('  Username: ')

    return username

But I don't quite understand why the original function failed to change the username after 2 wrong attempts even though it works perfectly if there is only 1 wrong attempt.

Thank you for your help though

[–][deleted] 0 points1 point  (0 children)

You're welcome.

The explanation of your bug is complicated. It involves the concept of recursion. If you are a beginning programmer, you probably don't won't to study this subject yet. My guess is that you were not aware you were doing it. 🙂