Home > OS >  How do I make my if statement actually do something
How do I make my if statement actually do something

Time:09-17

def attempt_function():
    number_of_attempts = 1
    saidpassword = ""
    if number_of_attempts > 3:
        print("You have entered the wrong password too many times, please try again later")
    saidpassword = input("the password you entered is incorrect, please try again\n")
    if saidpassword != password:
        number_of_attempts   1
        saidpassword = input("the password you entered is incorrect, please try again\n")

the if number_of_attempts > 3: doesn't seem to work when I use all of my attempts. It basically doesn't print.

CodePudding user response:

def attempt_function():
    number_of_attempts = 0
    saidpassword = ""
    
    while saidpassword != password:
        number_of_attempts   1
        saidpassword = input("the password you entered is incorrect, please try again\n")
        if number_of_attempts > 3:
            print("You have entered the wrong password too many times, please try again later")
            break
        saidpassword = input("the password you entered is incorrect, please try again\n")

You will need a while loop to increase the number of attempts

CodePudding user response:

Not 100% sure without seeing more code, but is "attempt_function" being called after a password attempt? which at the top sets number_of_attempts = 1, so it goes from 1->2 and then resets to 1?

  • Related