loop = 1 Login_Attemp_Count = 0 password = \"hello\" while loop == 1: # part 1 -
ID: 3736640 • Letter: L
Question
loop = 1
Login_Attemp_Count = 0
password = "hello"
while loop == 1:
# part 1 - reading correct password
readPWD = raw_input("Please enter password:")
if readPWD != password:
print "That was not a valid password, please try again. "
Login_Attemp_Count = Login_Attemp_Count + 1
if Login_Attemp_Count == 3:
print "Password attempts reached 3 times, the program ends now. "
loop = 0
else:
print "Welcome to the second half of the program!"
name = raw_input("Please enter your name:")
if name == "Clairrem" or name == "clairrem":
print "What a great name!"
elif name == "Madonna" or name == "Cher":
print "May I have your autograph, please?"
else:
print name + ", that is a nice name."
loop == 0
Please help, I don't know what am I doing wrong. I need the program to ask me for a password and when I enter the correct one it should continue with the program, if i don't, I get 3 chances then the program terminates. Right now when I test it even if I entered the wrong password it still continues to do the program.
This is the output right now:
Please enter password:hi
That was not a valid password, please try again.
Welcome to the second half of the program!
Please enter your name:
Explanation / Answer
loop = 1
Login_Attemp_Count = 0
password = "hello"
while loop == 1:
# part 1 - reading correct password
readPWD = input("Please enter password:")
if readPWD != password:
print("That was not a valid password, please try again. ")
Login_Attemp_Count = Login_Attemp_Count + 1
else:#if correct password entered..
print("Welcome to the second half of the program!")
name = input("Please enter your name:")
if name == "Clairrem" or name == "clairrem":
print("What a great name!")
elif name == "Madonna" or name == "Cher":
print("May I have your autograph, please?")
else:
print(name + ", that is a nice name.")
loop == 0
if Login_Attemp_Count == 3:
print("Password attempts reached 3 times, the program ends now. ")
break#breaking program
output:
>>> ================================ RESTART ================================
>>>
Please enter password:hello
Welcome to the second half of the program!
Please enter your name:surya
surya, that is a nice name.
Please enter password:he
That was not a valid password, please try again.
Please enter password:hh
That was not a valid password, please try again.
Please enter password:hel
That was not a valid password, please try again.
Password attempts reached 3 times, the program ends now.
>>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.