我试着做一个程序,掷骰子并检查用户是否想继续掷骰子,如果不想,程序应该停止。不过,不管你输入什么,程序都会跳出循环。有人能解释一下为什么,给我一些提示,使程序更简单,工作?谢谢
import random
sideNumber = int(input("Enter the number of sides in the die: "))
print("Dice numbers: ")
while True:
print(random.randint(0, sideNumber))
print("Do you want to continue?")
response = input()
if response == "n" or "no":
break
使您的代码失败。这将检查
"no"
的布尔值是否为真,并且始终为真。替换为:那是因为
"no"
这个语句仍然是真的。你知道吗你应该做:
或更好:
相关问题 更多 >
编程相关推荐