【发布时间】:2021-08-25 10:48:56
【问题描述】:
我在做一个小游戏,由于某种原因这个功能不起作用。
while InstructionsNeeded != 'no' or InstructionsNeeded != 'yes':
print("please type yes or no")
InstructionsNeeded = input("Welcome to Dice Brawl. Do you need instructions:")
InstructionsNeeded = InstructionsNeeded.lower()
我在代码中提供了之前的输入,它工作得非常好。此外,当我查看 InstructionsNeeded 的值时,它会正常读取。
【问题讨论】:
-
InstructionsNeeded不能同时为“否”和“是”,因此其中一个 or 条件始终为真……想清楚。 -
“不会工作”在什么意义上?例如,您当前缺少
InstructionsNeeded的初始起始值。 -
我非常怀疑它是否能正常工作。您的条件始终为真,因为没有字符串可以同时等于
'no'和'yes'。它应该是 `while ... and ...: -
您可能只想将
InstructionsNeeded != 'yes'更改为InstructionsNeeded == 'yes'
标签: python input while-loop conditional-statements