TypeError: __init__() missing 2 required positional arguments. Why is _init()_ missing arguments when it's there?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



TypeError: __init__() missing 2 required positional arguments. Why is _init()_ missing arguments when it's there?


class Vehicle:
def __init__(self,vehicle_cost,vehicle_type):
self.__vehicle_id =None
self.__vehicle_type=vehicle_type
self.__vehicle_cost=vehicle_cost
self.__premium_amount=None


def set_vehicle_id(self,vehicle_id):
self.__vehicle_id=vehicle_id

def get_vehicle_id(self):
return self.__vehicle_id

def set_vehicle_type(self,vehicle_type):
self.__vehicle_type=vehicle_type

def get_vehicle_type(self):
return self.__vehicle_type

def set_vehicle_cost(self,vehicle_cost):
self.__vehicle_cost=vehicle_cost

def get_vehicle_cost(self):
return self.__vehicle_cost

def set_premium_amount(self,premium_amount):
self.__premium_amount=premium_amount

def get_premium_amount(self):
return self.__premium_amount

def display_vehicle_details(self):
print("Vehicle Id is",self.__vehicle_id)
print("Vehicle Type is",self.__vehicle_type)
print("Vehicle Cost is",self.__vehicle_cost)

def calculate_premium(self):
if(self.__vehicle_type =="Two Wheeler"):
self.__premium_amount=self.__vehicle_cost-self.__vehicle_cost*0.98
print(self.__premium_amount)
elif(self.__vehicle_type =="Four Wheeler"):
self.__premium_amount=self.__vehicle_cost-self.__vehicle_cost*0.94
print(self.__premium_amount)
else:
print("Error: Wrong Vehicle type")


obj=Vehicle(105000, "Two Wheeler")
obj.calculate_premium()





As you got an exception/error, post the line it occurred on and the full exception/error details. Please edit these details in or we may not be able to help. I cannot replicate your issue - output 2100.0.
– AChampion
Aug 10 at 4:34



2100.0





Please see: How do I ask a good question?
– U9-Forward
Aug 10 at 4:34





Agree with @AChampion The output for me is also 2100.0
– U9-Forward
Aug 10 at 4:38


2100.0





Just a shot in the dark: are you testing it from python console while editing it in parallel?
– bereal
Aug 10 at 4:41





Yes, i am getting the desired output as 2100.0 . But, the platform has several inbuilt test cases. None of the logical lest cases is passing stating the error TypeError: __init__() missing 2 required positional arguments: 'vehicle_cost' and 'vehicle_type'. What could possibly be missing ?
– Sagar Srivastava
Aug 10 at 4:44




1 Answer
1



There is no error on my side. Your code is correct and it gave me output 2100.0.



Try to rename your file and make a new file with .py extension and run with python filename.py command on console instead of trying directly on console.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS