如何检查三个值是否相等,并基于此打印输出

2024-10-02 22:36:20 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我制作了一个命令终端,可以发送电子邮件,告诉你时间,甚至生成密码。无论如何,关键是,一个点上的大量代码意味着至少有一部分注定会失败,而我的代码中的这一部分目前是slots命令。老虎机命令是一个假的赌博游戏。问题是当检查某人是否真的赢了。当某人赢得老虎机游戏时,它会打印“你赢了!”否则会告诉你你输了,但它总是说用户输了。下面是实际需要的代码(不想让您浏览345行代码)


import random

def slots_p5():
    print("  " + slots_p2)
    print("» " + slots_p3)
    print("  " + slots_p4)


def find( slotOne, slotTwo, slotThree):
    if slotOne == slotTwo == slotThree:
        print ("\nYou win")
    else:
        print ("\nUnfortuneatly, you lose!")

slots = ["💎","💵","💰","7️⃣"]
slotOne = (random.choice(slots))
slotTwo = (random.choice(slots))
slotThree = (random.choice(slots))
slots_p2 = (random.choice(slots) + random.choice(slots) + random.choice(slots))
slots_p3 = slotOne + slotTwo + slotThree
slots_p4 = (random.choice(slots) + random.choice(slots) + random.choice(slots))

slots_p5()
find( slotOne, slotTwo, slotThree,)
slots_p2 = (random.choice(slots) + random.choice(slots) + random.choice(slots))
slots_p3 = slotOne + slotTwo + slotThree
slots_p4 = (random.choice(slots) + random.choice(slots) + random.choice(slots))
slotOne = (random.choice(slots))
slotTwo = (random.choice(slots))
slotThree = (random.choice(slots))

Tags: 代码命令游戏defrandomprintp2choice
2条回答

它很好用。由于它随机生成插槽,并且所有插槽必须相同,因此您肯定不会获得很多胜利。这都是关于概率的

您的代码对我来说运行得很好,您必须多次运行代码才能得到一个连续有三个的情况,但是如果您运行大约100次,就会发生这种情况。确实是语法

if slotOne == slotTwo == slotThree:

当得知它可以工作时,我很惊讶,但它确实可以

相关问题 更多 >