[英]Why does the first print statement's string gets printed in python?
while True:
print("HI , TELL YOUR NAME")
name = input()
if name != 'anwar':
continue
print("your password , please")
password=input()
if password != 'bull':
break
print("access granted")
所以这里的问题是当我收到 output 时,我得到第一个打印语句的字符串是
--------------- output -------------
HI , TELL YOUR NAME
anwar
your password , please
bull
access granted
HI , TELL YOUR NAME
我不想再次打印第一条语句..
当我查看我的书时,我看到相同的程序打印完美..
Python 3.6
1 while True:
2 print('Who are you?')
3 name = input()
4 if name != 'Joe':
5 continue
6 print('Hello, Joe. What is the password? (It is a fish.)')
7 password = input()
8 if password == 'swordfish':
9 break
10 print('Access granted.')
output 是我真正想要的......
-------------- output ----------
Who are you?
Joe
Hello, Joe. What is the password? (It is a fish.)
swordfish
Access granted.
请注意第一句话“你是谁?” 在程序结束时不打印。
正确的密码是在正确的密码上破解,而如果密码不匹配,您就是在破解。 所以它会一直循环,直到你输入错误的密码
if password != 'bull':
应该
if password == 'bull':
打破公牛的循环
因为你在测试
if password != 'bull':
虽然您的书示例使用==
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.