让while循环在Python中继续
我正在尝试做一个小程序,它可以告诉你是否输入了正确的密码,并一直要求输入正确的密码,直到输入为止。正确的密码是“Secret” 我尽可能地创建我的while循环。它会要求输入密码,并要求再次输入密码,但无论您第一次输入的密码是否正确,它都会这样做。我哪里做错了?如果我第一次输入了正确的密码,我如何让它中断?我如何让它一直询问密码,直到输入正确 这是我目前的代码:让while循环在Python中继续,python,loops,while-loop,Python,Loops,While Loop,我正在尝试做一个小程序,它可以告诉你是否输入了正确的密码,并一直要求输入正确的密码,直到输入为止。正确的密码是“Secret” 我尽可能地创建我的while循环。它会要求输入密码,并要求再次输入密码,但无论您第一次输入的密码是否正确,它都会这样做。我哪里做错了?如果我第一次输入了正确的密码,我如何让它中断?我如何让它一直询问密码,直到输入正确 这是我目前的代码: password = raw_input('What is the password? ') correctPassword = 'S
password = raw_input('What is the password? ')
correctPassword = 'Secret'
tryAgain = raw_input ('Enter password again ')
password
while password == False:
print 'Enter password again '
if password == correctPassword:
print 'You are in!'
break
请尝试以下代码:-
password= raw_input('What is the password? ')
correctPassword= 'Secret'
while password != correctPassword:
password = raw_input ('Enter password again ')
print "Success"
这将执行while循环,直到while循环中输入的密码不等于正确的密码。以下是正确的代码
correctPassword= 'Secret'
while True:
password= raw_input('What is the password? ')
if password == correctPassword:
print 'You are in!'
break
print 'Enter password again '
这是我的密码
password = 'password'
Get_password = input("Enter the password: ")
while Get_password != password:
print("the password you entered is not correct, enter the correct password")
break
print("You are logged in!")
没有语法错误。试着用通俗易懂的英语注释你的代码,看看它是否符合你的要求。@pazza:这是rohit给出的一个很好的解决方案。您需要做的是将密码与正确的密码字符串进行比较。只有这样你才能说它是否正确。谢谢!这是什么意思!=告诉它做什么?@Pazzaythonnewbie告诉它,而密码不等于正确的密码。你的代码不正确。尝试输入正确的密码……在“进入”之前,您必须输入三次密码