0

I'm beginner with Python. I know only C++/C# so... My problem is append to my array some object which is Card with 2 parameters, card has color and value

part of code doesn't work

class Game: 
    table = []
    ....
    def play(self, *players):
        for singlePlayer in players:
            self.table.append(singlePlayer.throwCard())

function throwCard() in Player

def throwCard(self):
    cardToThrow = self.setOfCards[0]
    del self.setOfCards[0]
    return cardToThrow

"main"

player1 = Player()
player2 = Player()
game = Game()
game.play([player1, player2])

Do you have some suggestions?

AttributeError: 'list' object has no attribute 'throwCard'

21koizyd
  • 1,843
  • 12
  • 25

2 Answers2

2

try changing:

def play():

to:

def play(self,players):

should do it.

Rayhane Mama
  • 2,374
  • 11
  • 20
1
class Game:
    # ...
    def play(self, *players):
        # ...

this play method requires arguments to be flat, not giving a list explicitly. I mean, you should ...

# your main
game.play(player1, player2)

check this SO post.

Leonard2
  • 894
  • 8
  • 21