2024-05-29 04:28:05 发布
网友
secret_word = "giraffe" guess = "" while guess != secret_word: guess = input("Enter your guess: ") print("Bravo, you've guessed it right!")
你的原始代码在python上为我工作。您可以尝试去掉前导空格和尾随空格,使其更健壮
secret_word = "giraffe" guess = "" while guess.strip() != secret_word: guess = input("Enter your guess: ") print("Bravo, you've guessed it right!")
如果您使用的是python2解释器,那么由于语法的变化,它将无法正常工作;因此,您可以编辑代码使其与python2兼容。或者您可能在命令行中调用了错误的终端,以确保它是python 3,您通常可以执行python3 my_program.py来显式使用python 3
python3 my_program.py
secret_word = "giraffe" guess = "" while guess != secret_word: guess = raw_input("Enter your guess: ") print "Bravo, you've guessed it right!"
干杯
你的原始代码在python上为我工作。您可以尝试去掉前导空格和尾随空格,使其更健壮
如果您使用的是python2解释器,那么由于语法的变化,它将无法正常工作;因此,您可以编辑代码使其与python2兼容。或者您可能在命令行中调用了错误的终端,以确保它是python 3,您通常可以执行
python3 my_program.py
来显式使用python 3干杯
相关问题 更多 >
编程相关推荐