anonymous
  • anonymous
Python: Classes : Can someone tell me why my "Remove Queen of Clubs" is not working in the attached program?
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
You forgot to attach the program.
anonymous
  • anonymous
anonymous
  • anonymous
Thanks!

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
When you're storing each card in the deck, what you're storing are card objects, each is a specific instance. When you create a new one and don't add it to the deck, it's not finding the exact card. The problem is that it doesn't distinguish between whether a card is the same based on the value, it distinguishes them based on where they're stored in memory. Here's some console output to demonstrate the differences python sees: >>> Card("Q", "C") <__main__.Card object at 0x02BD1ED0> >>> Card("Q", "C") <__main__.Card object at 0x02BD1FF0> >>> Card("Q", "C") <__main__.Card object at 0x02BD1C10> >>> Card("Q", "C") <__main__.Card object at 0x02BD1FB0> >>> Card("Q", "C") <__main__.Card object at 0x02BD1ED0> >>> Card("Q", "C") <__main__.Card object at 0x02BD1FF0> Card("Q", "C") Each of these cards has identical value but the objects are not identical. To remove a card using the remove function, you need to remove the same card you inserted - the same object from the same address. You can check every card and remove the one with the correct rank/suit combo. Here's the code to do that: def removeCard(self, cardToRemove): for card in self.cards: if card.suit == cardToRemove.suit and card.rank == cardToRemove.rank: self.cards.remove(card)
anonymous
  • anonymous
Thanks. That made complete sense, and worked like a charm.

Looking for something else?

Not the answer you are looking for? Search for more explanations.