Reputation: 1
I have this assignment: - Write an error-trap condition loop that asks the user for username and password inputs iteratively, until correct values are entered.
this is what I wrote so far:
while x in range(2):
x = x + 1
if q1==username and q2==password:
print("you entered the enchanted palace")
break
else:
print("wrong username/password, try again")
q1 = input("enter username: ")
q2 = input("enter password: ")
I really don't know how to approach the third clause.
Upvotes: 0
Views: 63
Reputation: 77827
You're so close:
while
and increment with for x in range(3):
WIth a couple of simple code updates ...
valid = False
for tries in range(3):
if q1==username and q2==password:
print("you entered the enchanted palace")
valid = True
break
else:
print("wrong username/password, try again")
q1 = input("enter username: ")
q2 = input("enter password: ")
if not valid:
print("wrong username/password, contact a system administrator”)
Upvotes: 2