我正在学习Python,在while循环方面遇到了问题。下面有一个示例代码,它包含一个while循环。我要做的是打印“哈!你永远不会猜到“每次正确的名字没有被预测,但我也希望代码打印”不!你怎么猜到的?“当预测到正确的名字时。我一直在玩它,它做我想做的,但我必须测试我的代码系统,它说这是不正确的,我的程序试图读取更多的输入比它应该需要的。任何帮助都将不胜感激!你知道吗
print("You will never win the game, for Scooby dooby doo! is my name.")
rumple = input("Guess my name: ")
while rumple != "Rumplestiltskin":
print("Ha! You'll never guess!")
rumple = input("Guess my name: ")
print('No! How did you guess?')
假设任务只有一个
input
函数,您可以将while循环改为这会将
input
函数放入while循环,而不需要事先初始化rumple变量。你知道吗你用哪种系统?我测试了你的代码,在我更正了缩进之后,我没有得到任何错误或警告。你知道吗
我的结果:
相关问题 更多 >
编程相关推荐