Correct a Python Code

Traceback (most recent call last):
File “C:/Python34/tasks/classCar.py”, line 8, in
cObj1 = Car(“Ford”, “Black”)
TypeError: object() takes no parameters

I am supposed to correct the program without changing the main program , but I cannot seem to find the problem



class Car(object):
   def display(self):
        print("Make:", self.make)
        print("Colour:", self.colour)
        print("Wheels:", Car.numwheels)

#main program
cObj1 = Car("Ford", "Black")
cObj1.display()


Hi @tagsolver28368,

Within the Car class definition, you need to create a class variable named numwheels and an appropriate __init__ method. Assign the value 4 to the numwheels class variable. The __init__ method needs have three parameters, which could be self, make, and colour, and it must use them to initialize a make and a colour instance variable.

Give it a try and post your code.

EDITED September 3, 2017 to revise suggested names of __init__ method parameters.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.