while True:
print ('What is your name')
name = input()
if name == 'Joe':
continue
else:
break
print ('What is the password')
password = input()
if password == '123':
break
print ('Permission Granted')
每当我输入除Joe之外的东西,它就会把我带到最后一行。我是编程的新手,所以任何帮助都会受到赞赏。
答案 0 :(得分:1)
如果我理解正确,那就是你的代码逻辑错了。尝试:
while True:
print ('What is your name')
name = input()
if name != 'Joe':
continue
print ('What is the password')
password = input()
if password == '123':
break
print ('Permission Granted')
答案 1 :(得分:1)
听起来你想在输入'Joe'之前继续询问名字。获得所需名称后,请检查密码。在这种情况下,请尝试:
while True:
name = input('What is your name? ')
if name != 'Joe':
continue
password = input('What is the password? ')
if password == '123':
print('Permission granted')
break
答案 2 :(得分:1)
也许这有帮助吗?
while True:
print ('What is your name')
name = input()
if name != 'Joe':
continue # if the name is not equal to 'Joe', go to the beginning of the loop
print ('What is the password')
password = input()
if password == '123':
print ('Permission Granted') # print this if the password is correct
break # if the password equals '123', exit the while loop
答案 3 :(得分:0)
尝试更改"输入()" to" raw_input()"。但是while循环会不断询问"你叫什么名字"如果你继续输入" Joe"
我认为这是你正在寻找的东西。
while True:
print ('What is your name')
name = raw_input()
if name == 'Joe':
print ("What is the password")
password = raw_input()
if password == '123':
print ('Permission Granted')
break
else:
continue
else:
continue