# [Tutor] inheritance problem

Roelof Wobben rwobben at hotmail.com
Fri Oct 1 09:39:39 CEST 2010

>>>
>>> I assigned a card by this code :
>>>
>>> def deal(self, hands, num_cards=999):
>>> num_hands = len(hands)
>>> for i in range(num_cards):
>>> if self.is_empty(): break # break if out of cards
>>> card = self.pop() # take the top card
>>> hand = hands[i % num_hands] # whose turn is next?
>>> hand.add(card) # add the card to the hand
>>>
>
> No this code assigns several HANDS not just cards.
> The code that assigns a card is inside this function, but
> you need to narrow it down to the specific lines assigning the card.
>

Oke,

The lines that assign card is :

hand = hands[i % num_hands] # whose turn is next?
hand.add(card) # add the card to the hand

The first one takes care to who a card is assigned and the second one assigned it to that person.

>>>> Where are the cards stored? How would you get the first card from
>>>> the collection? Does that work?
>>>
>>> The cards are stored in a directory named cards.
>
> Correct. So how do you get a card from the collection stored
> in self.cards?

This is not correct. Card is a list and not a directory. See this : self.cards = []

>> I make a big mistake.
>> Both card and hands are lists and pop can be used on a list.
>
> That's not a mistake, lists are objects too.

oke, but I confused two objects and that is a mistake.

>
>> So as Joel said in this rule card = self.pop() there is no list
>> named so I think it must be self.hands.pop()
>
> If you want to assign a card and cards are stored in self.cards
> why would you use self.hands.pop()?
> Surely it should be self.cards.pop()?

It is.
I know that because self.hands is not working.

Now Im busy to make this difficult exercise of writing print_hands()
But thanks for the time and explantion.
OOP is difficult to understand I find.

Roelof