Reputation: 169
An empty list is given, and I am trying to make a function which will identify player so that player1's cards will be added to left side of the empty list, and player2's cards will be added to right side of the empty list. Right now I have this function:
class OnTable:
def __init__(self):
self.__cards = []
def place(self,player,card):
if player == 'player2':
self.__cards.append(card)
elif player == 'player1':
self.__cards.insert(0,card)
def __str__(self):
list1 = '['
for item in self.__cards:
list1 += (str(item)+' ')
list1 = re.sub(' ', ' ', list1.strip())
return list1 + ']'
however, after I run this function using :
table = Ontable()
table.place(player1,card)
if only given me back an empty list...with nothing inside, is there a way I can let function know who is the player? Thanks you!
Upvotes: 0
Views: 50
Reputation: 193
table.place(player1,card)
Should be changed to table.place('player1','Ace of Hearts')
. Player 1 should be a string according to your place function.
Upvotes: 2