如何创建未知数量的变量?可能吗

时间:2019-03-24 21:07:19

标签: python class variables

我已经和python搞混了几个月。我想知道是否有任何方法可以缩短这段代码?我正在制作纸牌游戏,希望用户能够选择对手的数量。谢谢

    def __init__(self,usedCards):
        self.cards = [player]
        for i in range(52//playerNo):
            card = pickCard(usedCards)
            cards.append(card)
            usedCards.append(card)

playerNo = pushChoice("Pick the number of players you want to play against (up to 5)","integer",1,5)
player2 = player(usedCards)
if playerNo > 2:
    player3 = player(usedCards)
if playerNo > 3:
    player4 = player(usedCards)
if playerNo > 4:
    player5 = player(usedCards)
if playerNo > 5:
    player5 = player(usedCards)
if playerNo > 6:
    player6 = player(usedCards)```

0 个答案:

没有答案