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")
所以这里的问题是当我收到输出时,我得到了第一个打印语句的字符串
---------------输出-------------
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.')
输出是我真正想要的........
--------------输出----------
Who are you?
Joe
Hello, Joe. What is the password? (It is a fish.)
swordfish
Access granted.
请注意第一句话“你是谁?” 在程序结束时不打印。