Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

You forgot to attach the program.
Thanks!

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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)
Thanks. That made complete sense, and worked like a charm.

Not the answer you are looking for?

Search for more explanations.

Ask your own question