9/11


#1

My Code:

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        return 'This is a %s %s with %s MPG.' % (self.color, self.model, str(self.mpg))
    def drive_car(self):
        self.condition = "used"

my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition

class ElectriCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        self.model=model
        self.color=color
        self.mpg=mpg
        self.battery_type=battery_type
        
my_car=ElectricCar("Ford", "black", 20, "molten salt")

Error:

Traceback (most recent call last):
File "python", line 24, in
TypeError: ElectricCar() takes exactly 5 arguments (4 given)

Line 24 is my_car=ElectricCar("Ford", "black", 20, "molten salt")

I'm not sure why it's asking for 5 arguments. Please help!


#2

It looks to me like you are sending 5 arguments, the object itself and the 4 other arguments. But clearly you're not since you're getting that error saying otherwise. You've also misspelled the class's name. Hard to tell what else is off since your formatting is off, take care that the code shows up properly when showing it to others.


#3
class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        return 'This is a %s %s with %s MPG.' % (self.color, self.model, str(self.mpg))
    def drive_car(self):
        self.condition = "used"

my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition

class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        self.model=model
        self.color=color
        self.mpg=mpg
        self.battery_type=battery_type
        
my_car=ElectricCar("Ford", "black", 20, "molten salt")

It was the misspelling. This code works. Thanks!


#4

@robengel87,

1.

Re-edit your post....
- Select your code and then =click= on the </> symbol of the editor
- re-edit your code with the proper indention

2.

The init-keyword is written as __init__

3.

have a goog look at the word

ElectriCar


#5

Correct one:

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        return 'This is a %s %s with %s MPG.' % (self.color, self.model, str(self.mpg))
    def drive_car(self):
        self.condition = "used"

my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition

class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        self.model=model
        self.color=color
        self.mpg=mpg
        self.battery_type=battery_type
        
my_car=ElectricCar("Ford", "black", 20, "molten salt")

#6

@flamingswifferduster,
Now if you re-edit your Post
by =selecting your code=
and then=click= on the </>-symbol of this editor
your code will be placed in the pre-code mode,
and you are able to make right indentation's...!!!


#7

Thank you!
...................................................... <= to meet 20 char rec