#๐ What sort of methods can I use to implement under a certain class?
32 messages ยท Page 1 of 1 (latest)
@timid cloud
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
File card.py has two enum classes: CardColor and CardLabel. You must now modify it to implement the Card class with the following instance attributes:
color - an enum value representing the color of the card.
label - an enum value representing the label of the card.
You must also modify file player.py to implement the Player class with the following attributes:
name - a string representing the name of the player.
position - an integer representing the position of the player in the game. The player with the lowest position goes first. Positions start at 0.
hand - a ordered collection of Card objects representing the cards in the player's hand. This list must be ordered by color of the card, then by card label in an increasing order according to the enum values. If the card has the same color and label, then consider the first card added to the hand to be the one with the lower index.
add_card(self, card: Card) - a method that takes a Card object as an argument and adds it to the hand. The method should return None. Assume that the card being passed is a valid card.
play_card(self, index: int) - a method that takes an integer as an argument and removes the card at the given index from the player's hand. The method should return the card that was removed from the player's hand.
len(self) - a method that returns the number of cards in the player's hand.
getitem(self, index: int) - a method that takes an integer as an argument and returns the card at the given index in the player's hand.
NOTE - For both of these classes, please add additional helper methods if you think they are necessary (including a str method to help with debugging).
Can you rephrase your question? It doesn't seem to make much sense.
umm can you take a look at my code first?
I cannot seem to make sense of the question
I did.
can it be more concise
take UNO for example, there's like certain colors and labels such as One to Nine{Red, Blue, Green, Yellow}, Reverse Card {Red, Blue, Green, Yellow}, etc.
I'm now having trouble implementing the Card class with both the color and label
which are the attributes
You seem to already have such a class?
what do you mean?
You already have
class Card:
def __init__(self, color: CardColor, label: CardLabel) -> None:
self.color = color
self.label = label
Why do you have raise NotImplementedError in there? And the self.color = color and the line below it need to go under the docstring. The docstring must be the first thing in the method.
The fact that you broke the docstring might be messing with an autograder (I'm assuming you're using an autograder).
I see
raise NotImplementedError was just there and how do I proceed after placing self.color = color under the docstring?
raise NotImplementedError was just there
They probably put it there for you to replace it with the actual code. As its name suggests, it's a placeholder to indicate that code hasn't been written yet.
how do I proceed
What's the current problem you're trying to solve?
Ok
thx for assisting me anyways
You're welcome.
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.