secret_word = "giraffe"
guess = ""
while guess != secret_word:
guess = input("Enter your guess: ")
print("Bravo, you've guessed it right!")
答案 0 :(得分:0)
您的原始代码在python上为我工作。您可以尝试摆脱前导空格和尾随空格的影响,使其更强大。
secret_word = "giraffe"
guess = ""
while guess.strip() != secret_word:
guess = input("Enter your guess: ")
print("Bravo, you've guessed it right!")
如果您使用的是Python 2解释器,由于语法更改,它将无法正常工作;因此,您可以将代码编辑为与Python 2兼容。或者您可能在命令行中调用了错误的终端,以确保它是python 3,您通常可以执行python3 my_program.py
来显式使用python 3。
secret_word = "giraffe"
guess = ""
while guess != secret_word:
guess = raw_input("Enter your guess: ")
print "Bravo, you've guessed it right!"
干杯!