我正在学习python,并尝试制作剪刀石头布游戏。我在这里停留在一个问题上。我不知道如何解决它。所以问题是当我输入“ paper”和“ ranval”变量选择2(剪刀)时,我仍然赢。非常感谢您的宝贵时间。有代码:
import random
while True: # 0 rock, 1 paper, 2 scissors
while True:
rps = [0, 1, 2]
ranval = random.choice(rps)
choice = str(input("(r)ock, (p)aper or (s)cissors?"))
if choice.lower() == "r" or "rock":
if ranval == 0:
print("TIE!", ranval)
break
elif ranval == 1:
print("YOU LOST!", ranval)
break
elif ranval == 2:
print("YOU WON!", ranval)
break
if choice.lower() == "p" or "paper":
if ranval == 0:
print("YOU WON!", ranval)
break
elif ranval == 1:
print("TIE!", ranval)
break
elif ranval == 2:
print("YOU LOST!", ranval)
break
if choice.lower() == "s" or "scissors":
if ranval == 0:
print("YOU LOST!", ranval)
break
elif ranval == 1:
print("YOU WON!", ranval)
break
elif ranval == 2:
print("TIE!", ranval)
break
if choice.lower() == "e" or "exit":
exit()
答案 0 :(得分:2)
if choice.lower() == "r" or == "rock":
if choice.lower() == "r" or choice.lower() == "rock":
是不同的。
让您的if语句看起来都像这样
if choice.lower() == "r" or choice.lower() == "rock":