0

I'm getting a Vehicle.__init__(self, make, model, year, mileage, price, doors) TypeError: __init__() takes exactly 6 arguments (7 given). I'm only entering 6 however so i'm not sure what is going on. I'd also like some help with my inventory function. I'm trying to make a program that will allow a user to input different vehicles into an inventory along with their certain attributes. I'm awfully close to getting this done, but could use some extra eyes to hopefully see what i cannot. Any advice would be immensely appreciated.

class Vehicle:

    def __init__(self, make, model, year, mileage, price):
        self.__make = make
        self.__model = model
        self.__year = year
        self.__mileage = mileage
        self.__price = price

    def iMake(self, make):
        self.__make = make

    def iModel(self, model):
        self.__model = model

    def iYear(self, year):
        self.__year = year

    def iMileage(self, mileage):
        self.__mileage = mileage

    def iPrice(self, price):
        self.__price = price

    def getMake(self):
        return self.__make

    def getModel(self):
        return self.__model

    def getYear(self):
        return self.__year

    def getMileage(self):
        return self.__mileage

    def getPrice(self):
        return self.__price



class Car(Vehicle):

    #number of doors
    def __init__(self, make, model, year, mileage, price, doors):
        Vehicle.__init__(self, make, model, year, mileage, price, doors)
        self.__doors = doors
    def iDoors(self, doors):   
        self.__doors = doors
    def gDoors(self):
        return self.__doors


class Truck(Vehicle):

    #drive type (2 or 4 wheel drive)
    def __init__(self, make, model, year, mileage, price, drive):
        Vehicle.__init__(self, make, model, year, mileage, price, drive)
        self.__drive = drive
    def iDrive(self, drive):   
        self.__drive = drive
    def gDrive(self):
        return self.__drive


class SUV(Vehicle):

    #passanger capacity
    def __init__(self, make, model, year, mileage, price, passengers):
        Vehicle.__init__(self, make, model, year, mileage, price, passengers)
    def capacity(self, passengers):
        self.__passengers = passengers
    def gCapacity(self):
        return self.__passengers


class Inventory:

    def __init__(self, list1 = []):
        self.list1 = list1[:]
    def addVehicle(self, vehicle):
        self.list1.append(vehicle)
    def display(self):
        print("The inventory count is ", len(self.list1))
        for vehicle in self.list1:
            vehicle.display()


def main():

    inventory = Inventory()
    classType = input('Is the vehicle a car, truck, or suv?  ')
    if classType == 'car':
        make = input('Please enter the make of the car: ')
        model = input('Please enter the model of the car: ') 
        year = input('Please enter the year of the car: ')
        mileage = input('Please enter the mileage of the car: ')
        price = input('Please enter the price of the car: ')
        doors = input('Please enter the amount of doors on the car: ')
        car = Car(make, model, year, mileage, price, doors)
        print('Make: ', car.gMake())
        print('Model: ', car.gModel())
        print('Year: ', car.gYear())
        print('Mileage: ', car.gMileage())
        print('Price: ', car.gPrice())
        print('Number of doors: ', car.gDoors())
        print()
    elif classType == 'truck':
        make = input('Please enter the make of the truck: ')
        model = input('Please enter the model of the truck: ') 
        year = input('Please enter the year of the truck: ')
        mileage = input('Please enter the mileage of the truck: ')
        price = input('Please enter the price of the truck: ')
        drive = input('Please enter 2 wheel or 4 wheel drive for the truck: ')
        truck = Truck(make, model, year, mileage, price, drive)
        print('Make: ', truck.gMake())
        print('Model: ', truck.gModel())
        print('Year: ', truck.gYear())
        print('Mileage: ', truck.gMileage())
        print('Price: ', truck.gPrice())
        print('Type of drive: ', truck.gDrive())
        print()
    elif classType == 'suv':
        make = input('Please enter the make of the suv: ')
        model = input('Please enter the model of the suv: ') 
        year = input('Please enter the year of the suv: ')
        mileage = input('Please enter the mileage of the suv: ')
        price = input('Please enter the price of the suv: ')
        passengers = input('Please enter the capacity of the suv: ')
        suv = SUV(make, model, year, mileage, price, drive)
        print('Make: ', suv.gMake())
        print('Model: ', suv.gModel())
        print('Year: ', suv.gYear())
        print('Mileage: ', suv.gMileage())
        print('Price: ', suv.gPrice())
        print('Number of passengers: ', suv.gCapacity())
        print()
    cont = input('Would you like to add another vehicle?  y/n  ')
    if cont == 'y':
        main()
    elif cont == 'n':
        inventory.display()

1 Answer 1

2

You're passing all the arguments from Car.__init__ to Vehicle.__init__. The problem is that those two functions don't have the same signature.

class Car(Vehicle):
    #number of doors
    def __init__(self, make, model, year, mileage, price, doors):
        Vehicle.__init__(self, make, model, year, mileage, price)  # no doors
        self.__doors = doors
Sign up to request clarification or add additional context in comments.

2 Comments

Why not use super(Vehicle, self).__init__(make, model, year, mileage, price)?
@qwertynl -- At least for learning purposes, I think this version is more instructive. No need to pull the magic of super into it. Generally, I don't recommend blind use of super because of the discussion here. That doesn't mean that it has no place -- It certainly does... But more often than not, I tend to avoid it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.