Dec-24-2021, 05:05 AM
(This post was last modified: Dec-24-2021, 05:06 AM by CompleteNewb.)
(Dec-24-2021, 02:02 AM)BashBedlam Wrote: We can't run your code becausestraightfunction
,pairfunction
andflushfunction
are missing but I can help you understand why the variablehand
is throwing the error that you're getting.
Variables defined in a class before the__init__
method are called "class variables". They are called that because they are shared by every instance of that class. In the code below I show you how to set a class variable but more importantly, why you shouldn't try to use them the way that you are. The reason for this is becausePlayer.hand
is the same for bothplayer_one
andplayer_two
.
class Player : hand = [] def __init__ (self, number, chips) : self.number = number self.chips = chips player_one = Player (7, 11) player_two = Player (7, 13) Player.hand = [['1', 'H'],['2', 'D'],['3', 'C'],['4', 'S']] print (f'Hand for player one is {one.hand}.') print (f'Hand for player two is {two.hand}.')
Thanks for answering back. I really appreciate it. So i put them in the constructor? But what about the flop? Do i put the flop, turn and river as class variables and change it at every turn, because I can't pass variable as a argument in a function called inside a function inside a class?