[英]Issue with OR statement in Python while making simple dice rolling game
我是Python编程的新手,并且此程序中的or语句有问题。 当我在PyCharm中运行它并输入'roll'时,它可以工作。 但是当我使用“是”时,似乎什么也没做。 而input()==(“ roll”)或input()==(“ yes”):这是问题所在。 我想知道我在做什么错。 例如,当我仅使用一个命令roll时,它可以完美运行多次,就像我想运行它一样。
# this is a dice rolling game
import random
min = 1
max = 6
def roll_dice():
x = random.randint(min, max)
print(x)
print("Would you like to roll the dice?")
while input() == ("roll") or input() == ("yes"):
roll_dice()
print("Would you like to roll the dice again ?")
不要两次调用input()
。 调用一次并使用in
测试集合in
是否存在:
while input() in {'roll', 'yes'}:
...
如果您使用的是python2,请记住您将需要raw_input
,而不是input
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.