Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Last answered:

01 Mar 2024

Posted on:

29 Feb 2024

0

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?




1 answers ( 1 marked as helpful)
Instructor
Posted on:

01 Mar 2024

1

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

Submit an answer