Ask your own question, for FREE!
Classes 21 Online
OpenStudy (anonymous):

OldMaidGame : Why am I unable to add a card to a hand?

OpenStudy (anonymous):

Program file attached.

OpenStudy (rsmith6559):

Print the value of card in the method to make sure that it's what you expect.

OpenStudy (anonymous):

I am not sure I understood. I am printing the value of the card, and it is the top card in the deck, but the addCard method is giving an error.

OpenStudy (anonymous):

The addCard method isn't giving you an error. I tried running the code you attached, the exception says: Traceback (most recent call last): File "C:/Users/joshua/Documents/MIT/test.py", line 182, in <module> game.play(["Allen","Jeff","Chris"]) File "C:/Users/joshua/Documents/MIT/test.py", line 144, in play self.deck.deal([names],51) File "C:/Users/joshua/Documents/MIT/test.py", line 63, in deal hand.addCard(card) AttributeError: 'list' object has no attribute 'addCard' Note the last line where it says that 'list' object has no attribute addCard? That tells us that hand is a list and not a Hand or Deck object. In the lines above this we see that this happened in the self.deck.deal method. You can see the actual call here: File "C:/Users/joshua/Documents/MIT/test.py", line 144, in play self.deck.deal([names],51) Note that you are wrapping the list of names you passed in within a list. Then that list is being passed into the function. I'm pretty sure you meant to pass in self.hands. Moreover, you are going to need to call the method to remove cards rather then operating on cards itself when you run into the next error.

OpenStudy (anonymous):

Thanks. Could you attach your file, so that I can follow it better?

OpenStudy (anonymous):

Here's my new program, and it still does not add cards to the hands. The remove card from deck works though.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!