Resolved: Error In Calling Card Class
So after creating the Card class, upon running it, it keeps returning this error. t
Below is the code and error encountered.
class Card(object):
suits = {'d': 'Diamonds',
'h': 'Hearts',
's': 'Spades',
'c': 'Clubs'}
values = {1: 'Ace', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five',
6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten',
11: 'Jack', 12: 'Queen', 13: 'King'}
def _init_(self, value, suit):
self.value = value
self.suit = suit
def get_value(self):
return self.value
def get_suit(self):
return self.suit
def _str_(self):
my_card = str(self.value), + ' of ', + str(self.suit)
return my_card
my_card = Card(3,'h')
Error :
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-33-85e458f33b14> in <cell line: 1>()
----> 1 my_card = Card(3,'d')
TypeError: Card() takes no arguments
How can this be solved?
Hey Arowosegbe,
Thank you for reaching out!
Note that __init__()
is part of the so-called "dunder" methods. This means that it's defined with double underscores on each side. Therefore, if you change the following line of code from
def _init_(self, value, suit):
to
def __init__(self, value, suit):
your code should run with no errors.
Let me know if you encounter other issues and enjoy the rest of the course.
Kind regards,
365 Hristina