Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

halkazi Group Title

Python: Classes : Can someone tell me why my "Remove Queen of Clubs" is not working in the attached program?

  • one year ago
  • one year ago

  • This Question is Closed
  1. bdean20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    You forgot to attach the program.

    • one year ago
  2. halkazi Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    • one year ago
  3. halkazi Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks!

    • one year ago
  4. bdean20 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    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)

    • one year ago
  5. halkazi Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks. That made complete sense, and worked like a charm.

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.