

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
Not enough gems
Cost: 6 gems
1: Polymorphism
incomplete
2: Get Edges
incomplete
3: Overlap
incomplete
4: Dragon Area
incomplete
5: Polymorphism Review
incomplete
6: Operator Overloading
incomplete
7: Operator Overload Review
incomplete
8: Overriding Built-in Methods
incomplete
9: Polymorphism Practice
incomplete
10: Polymorphism Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Let's continue working on the card game we started in an earlier practice problem. Let's add some logic to our Card class to simplify comparing one instance of a Card to another.
To compare two cards, we need a set of rules.
RANKS and SUITS define the order. The higher the index, the higher the value.Card("Ace", "Hearts") > Card("Queen", "Hearts") is True because "Ace" has a higher index than "Queen".Card("King", "Spades") > Card("King", "Hearts") is True because "Spades" comes after "Hearts" in the SUITS list.Complete the Card class:
ranks, and suits to help you compare them against each other. Keep in mind that a rank and a suit are just strings within a list.The .index list method is very useful when trying to determine the index of an element in a list.
For __eq__, check that other is a Card before reading its indexes. Python's isinstance(other, Card) is the usual way to do that.