0

I have tried to run this code but i keep getting this error. I dont know what is causing the error. Please can someone help me out?

class Dog():
    """ A simple attempt to describe a dog"""
def __init__(self, name, age):
    """ Initialize name and age attributes."""
    self.name = name
    self.age = age
def sit(self):
    """ Simulates a dog sitting in response to a command."""
    print(f"{self.name}.title() " + "is now sitting.")
def roll_over(self):
    """ Simulates a dog rolling over in response to a command."""
    print(f"{self.name}.title() " + " rolled over.")

my_dog = Dog('willie', 6)

print("My dog's name is " +  my_dog.name.title() + ".")
print("My dog is " + str(my_dog.age) + " years old.")

Error

[Running] python -u "/Volumes/Macintosh HD2/python_project/python_work/classes.py"
Traceback (most recent call last):
  File "/Volumes/Macintosh HD2/python_project/python_work/classes.py", line 14, in <module>
    my_dog = Dog('willie', 6)
TypeError: Dog() takes no arguments

[Done] exited with code=1 in 0.055 seconds
Guy
  • 46,488
  • 10
  • 44
  • 88
Samuel Antwi
  • 33
  • 1
  • 5

2 Answers2

1

It is simple- you have not indented anything after class Dog(). Indent it, and everything should be fine.

class Dog():
    """ A simple attempt to describe a dog"""
    def __init__(self, name, age):
        """ Initialize name and age attributes."""
        self.name = name
        self.age = age
    def sit(self):
        """ Simulates a dog sitting in response to a command."""
        print(f"{self.name}.title() " + "is now sitting.")
    def roll_over(self):
        """ Simulates a dog rolling over in response to a command."""
        print(f"{self.name}.title() " + " rolled over.")

    my_dog = Dog('willie', 6)

print("My dog's name is " +  my_dog.name.title() + ".")
print("My dog is " + str(my_dog.age) + " years old.")
Sid
  • 2,174
  • 1
  • 13
  • 29
0

In python indentation is important,

class Dog():, my_dog = Dog('willie', 6) This code lack in indentation,There are online indentation checker in case you find diffculty.

kvk30
  • 1,133
  • 1
  • 13
  • 33
  • Please can you provide me any useful site for indentation checker. I am using Visual studio code and the indentation is giving me headache. Thank you very much. – Samuel Antwi Aug 21 '19 at 12:14
  • https://stackoverflow.com/questions/1024435/how-to-fix-python-indentation, Hope this StackOverflow answer can give good insights. – kvk30 Aug 24 '19 at 07:01