[Python] How I change my code to give the user 3 attempts for the username and password

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I have attached a file which sums up what i need to add to my code, please someone help me

    enter image description here

    userNames = ["User1", "User2", "User3", "User4", "User5"]
    print("Welcome to AQA User Registration")
    for x in range(3):
    userName = input("New username: ")
    if userName in userNames:
    print("The username is already used")
    else:
    break
    for x in range(3):
    userPassword = input("Password (12 characters or more): ")
    if len(userPassword) < 12:
    print("The password is not long enough")
    else:
    break
    print("Your username is " + userName)
    print("Your password is " + userPassword)


    I tried to use "for x in range(2)" to repeat it 3 times but even if the user enters a different username, it still ends the program. It is not in this code because it is very messy. I spent 1 hour trying to figure it out and I couldn't do so I would be very grateful if someone could help me.

    Continue reading...

Compartilhe esta Página