所以我刚开始学习python,每周都会从朋友那里得到迷你课程。这周要做一个简单的老虎机游戏。老虎机中有 6 个项目,当出现 3 个或更多相同项目时,用户获胜。我试过下面的代码:
for i in slotScreen:
if slotScreen.count(i) == 3:
print('You got 3 of the same! You win!')
当列表中的第一项是同类 3 的一部分时,该代码有效,但如果三个元素都不是列表中的第一个,则该代码不起作用,如下所示:
slotScreen = ['lemon', 'cherry', 'lemon', 'lemon', 'pirate', 'bar'] # works
slotScreen = ['cherry', 'lemon', 'lemon', 'lemon', 'pirate', 'bar'] # not work
知道为什么会这样吗?
编辑:更多代码。当我应该收到 You win 3x 消息时,我收到了 You Lose 消息。
for i in slotScreen:
if slotScreen.count(i) == 6:
print('You win 10x your bet!!!')
x = x + int(bet) * 10
break
elif slotScreen.count(i) == 5:
print('You win 5x your bet!')
x = x + int(bet) * 5
break
elif slotScreen.count(i) == 4:
print('You win 4x your bet!')
x = x + int(bet) * 4
break
elif slotScreen.count(i) == 3:
print('You win 3x your bet!')
x = x + int(bet) * 3
break
elif slotScreen.count(i) <= 2:
print('Sorry you lose')
break