[Tutor] inheritance problem
alan.gauld at btinternet.com
Fri Oct 1 09:29:33 CEST 2010
"Roelof Wobben" <rwobben at hotmail.com> wrote
>>> So if the code you copied has an error how should it assign a
>> 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.
>>> 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
>> The error is telling me that the function pop does not exist for a
>> So solution is to find out which object contains pop and then
>> change the code.
> 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.
> 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()?
Author of the Learn to Program web site
More information about the Tutor