我之前问过类似的问题,但解决方案似乎不起作用。我正在编写一款掷骰子游戏,如果任何一个玩家的数字与计算机的数字匹配,则玩家获胜,并打印一条消息“你赢了”。否则,elif 语句意味着计算机获胜并打印“你输了”。我的问题是 elif 语句不会打印“你输了”。它只是不断打印“你赢了”。
import random
die1 = 0
die2 = 0
die3 = 0
roll1 = 0
roll2 = 0
roll3 = 0
def dice_roll():
dieroll = random.randint(1, 6)*2
return dieroll
for die in range(12):
die1 = int(input(f'Choose a number between 2 and 12: '))
die2 = int(input(f'Choose a number between 2 and 12: '))
die3 = int(input(f'Choose a number between 2 and 12: '))
roll1 = dice_roll()
roll2 = dice_roll()
roll3 = dice_roll()
if die1 or die2 or die3 == roll1 or roll2 or roll3:
print(f'Roll # 1 was {roll1}')
print(f'Roll # 2 was {roll2}')
print(f'Roll # 3 was {roll3}')
print(f'You Win! - Thanks for playing!')
elif die1 or die2 or die3 != roll1 or roll2 or roll3:
print(f'Roll # 1 was {roll1}')
print(f'Roll # 2 was {roll2}')
print(f'Roll # 3 was {roll3}')
print(f'You Lose! - Thanks for playing!')
慕容3067478
Smart猫小萌
一只斗牛犬
明月笑刀无情
相关分类