在我的 while 循环中,有一个选项“yes”会导致变量的输出,但它也会重复用户的“yes”输入。
# Print list of input options
options = ("""
Here is a list of your options besides "yes" or "no":
Help - Shows this list.
Go Back - Head back to the previous room.
""")
help = ["help", "h", "options"]
# Go Back
go_back = ["go back", "back"]
# Yes
yes = ["yes", "y"]
# No
no = ["no", "n"]
Begin = lines = ["Story start"]
while True:
understand = input("Do you understand?\n")
if understand.lower() in help:
print("\n")
print(help)
print("\n")
continue
elif understand.lower() in go_back:
print("\nSorry, there's nowhere to go right now. Try again.\n")
continue
elif understand.lower() in yes:
print("\n")
print(Begin)
break
else:
print(f"\nSorry, let's try this again.\n")
continue
print(understand)
我提前道歉,我对Python很陌生,我不知道如何格式化这个网站中的问题。
我询问玩家是否理解之前的指令,当我使用“yes”变量测试它时,它输出“Begin”变量,但由于某种原因,它之后也会重复用户输入的“yes”。像这样:
Do you understand?
Yes
[‘Story start’]
Yes
我无法找到为什么它在[‘故事开始’]之后重印“是”。
此外,我现在远离先进的方法,因为这是我正在为在线课程做的一个小项目
谢谢!
您在最后一个字符串中输入了“print(understand)”。同时将 print 移至第 31 行)也许您希望它成为一个函数?