All Courses

Someone guide please.

By Sde221876@gmail.com, 3 months ago
  • Bookmark
0

Someone guide please.

Code:

class vehicle:
    def __init__(self,name,color,max_speed,mileage):
        self.name = name
        self.color = "white"
        self.max_speed = max_speed
        self.mileage = mileage
class Bus(vehicle):
    pass
class Car(vehicle):
    pass
class Bike(vehicle):
    pass
obj = Bus("volvo",120,4)
obj1= Car("Wagnor",180,8)
obj2= Bike("pulsar",110,5)
print(f"Bus model name is {obj.name} with color {obj.color} and maximum speed is {obj.max_speed}")
print(f"Car model name is {obj1.name} with color {obj1.color} and maximum speed is {obj1.max_speed}")
print(f"Bike model name is {obj2.name} with color {obj2.color} and maximum speed is {obj2.max_speed}")

output:

TypeError                                 Traceback (most recent call last)
Cell In [2], line 14
     12 class Bike(vehicle):
     13     pass
---> 14 obj = Bus("volvo",120,4)
     15 obj1= Car("Wagnor",180,8)
     16 obj2= Bike("pulsar",110,5)

TypeError: vehicle.__init__() missing 1 required positional argument: 'mileage'


Python
Oops
Error
Typeerror
2 Answers
0
Hitendradixit18@gmail.com

You have taken 4 parameters in init but have passed only 3 check it while creating the objects

0
Goutamp777

The error message is indicating that there is a missing required argument in the constructor of the vehicle class. Specifically, the __init__ method of the vehicle class takes four arguments (name, color, max_speed, and mileage) but when creating the obj object of the Bus class, you are only passing in three arguments (name, max_speed, and mileage). To fix this, you need to pass in a value for the color argument when creating the obj, obj1, and obj2 objects.

Your Answer

Webinars

Live Masterclass on : "How Machine Get Trained in Machine Learning?"

Mar 30th (7:00 PM) 516 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More