World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Getting this error...pls explain
Code:
class Vehicle: def __init__(self,max_speed,mileage): self.max_speed = max_speed self.mileage = mileage def display(self): print(f'max_speed - {self.max_speed} and mileage - {self.mileage}') car = Vehicle("car",45,15) car.display()
output:
TypeError Traceback (most recent call last) Cell In [3], line 7 5 def display(self): 6 print(f'max_speed - {self.max_speed} and mileage - {self.mileage}') ----> 7 car = Vehicle("car",45,15) 8 car.display() TypeError: Vehicle.__init__() takes 3 positional arguments but 4 were given
This code is attempting to create an instance of the Vehicle class, but it is passing the wrong number of arguments to the class's constructor (init method). The constructor is defined to take two arguments (max_speed and mileage) but three arguments are being passed when the instance is created on line 7.
( "car", 45, 15)
It should be changed to
car = Vehicle(45,15)