I've been experimenting with some stuff, and ran into this problem. The user must enter a password and has 3 attempts to do so, otherwise he will be shut out. But I keep getting 6 attempts. I am aware that I can fix this but using pw_count < pw_attempt instead of pw_count <= pw_attempt. I just want to understand the logic behind it when I use <=
a1 = ""
a2 = ""
a3 = ""
pw_count = 0
pw_attempt = 3
pw = input("Please enter your password: ")
pwre = input("Please re-enter your password: ")
while pw != pwre and pw_count <= pw_attempt:
a1 = input("Your password doesn't match, please try again: ")
pw_count += 1
if a1 == pw:
break
else:
a2 = input("Your password doesn't match, please try again: ")
pw_count += 1
if a2 == pw:
break
else:
a3 = input("Your password doesn't match, please try again: ")
pw_count += 1
if a3 == pw:
break
if (pw == pwre and pw_count <= pw_attempt) or (a1 == pw and pw_count <= pw_attempt) or (a2 == pw and pw_count <= pw_attempt) or (a3 == pw and pw_count <= pw_attempt):
print("Password is confirmed")
else:
print("You have entered the wrong password too many times")
I just expect the program to prompt the user with 3 attempts instead of 6.