Last answered:

29 Feb 2024

Posted on:

16 Mar 2022

4

My answer to the task playing card

class card(object):
    suits = {'S':'Spades','C':'Clubs','H':'Hearts','D':'Diamonds'}
    values = {1:'Ace',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'10','J':'Jack','Q':'Queen','K':'King'}
    def __init__(self, value, suit):
        self.value = value
        self.suit = suit
    def get_value(self):
        return card.values[self.value]
    def get_suit(self):
        return card.suits[self.suit]
    def __str__(self):
        my_card = str(card.values[self.value])+' of '+str(card.suits[self.suit])
        return my_card

a = card(1, 'D')
a.__str__()

1 answers ( 0 marked as helpful)
Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

29 Feb 2024

0

Got the answer to it. 


used _init_ with one underscore at each end when it should have been __init__. 

Thanks

Submit an answer