I created a playing card object that has certain attributes of rank, suite and blackjack value.
The blackjack value part keep getting a TypeError that says I can't compare between instances of list
and int
. I'm not sure how to resolve (how to/if I can compare just the index of the list and then give it the blackjack value based on its index)?
Does the if/elif block belong within the bjValue() function or in the init() function?
Here's my code:
class Card:
"""playing card object where numeric rank, suit and blackjack values are stored"""
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
self.ranks = [None, "Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King"]
self.suits = {"d": "Diamonds",
"c": "Clubs",
"h": "Hearts",
"s": "Spades"}
def getRank(self):
"""returns the rank of the card"""
return self.rank
def getSuit(self):
return self.suits.get(self.suit)
def bjValue(self):
if self.rank > 1 or self.rank < 11:
self.value = self.rank
elif self.rank == "Ace":
self.value = 1
elif self.rank == "Jack" or self.ranks == "Queen" or self.ranks == "King":
self.value = 10
return self.value
def __str__(self):
return "%s of %s" % (self.ranks[self.rank], self.suits.get(self.suit))
c1 = Card(1,"s")
c2 = Card(11,"d")
print(c1) #expect Ace of Spades
print(c2) #expect Jack of Diamonds
c3 = Card(5,"c") #expect 5 of clubs
print(c3.getRank())
print(c3.getSuit()) #expect Five
print(c3.bjValue()) #expect 5
print(c3)
c4 = Card(1,"s")
print(c4)
Edit: So, I fixed my typo and I'm not getting anymore errors but I'm still getting the incorrect blackjack value for the Jack, Queen and King cards (I get their blackjack value back as their rank even though i have the if statement) and I don't understand where the flaw in my logic is...