You are probably trying to use the len
function on a Deck
object itself as opposed to using it on the instance variable deck
of a Deck
object. If d
is an instance of class Deck
, you should call len(d.deck)
, or even better, implement a getter method for self.deck
and use something like len(d.get_deck())
.
post-op-edit-edit:
You are trying to call shuffle
on the Deck
object itself as opposed to the list
deck
which is stored in your Deck
object. Part of the confusion probably comes from the fact that you decided to name the class Deck
and its instance variable deck
. If you want the list
deck
, you need to issue deck = Deck().deck
in your deal
function.
edit in response to comment:
Of course, you cannot call deal_card
on the list
deck
. You can do
def deal():
deckObject = Deck()
deckList = deckObject.deck
player = Hand()
dealer = Hand()
random.shuffle(deckList)
player.add_card(deckObject.deal_card())
player.add_card(deckObject.deal_card())
dealer.add_card(deckObject.deal_card())
dealer.add_card(deckObject.deal_card())
prompt()
The notation should hopefully make clear whats the Deck
object here and what's the deck
list
.