Найти - Пользователи
Полная версия: Проверьте, пожалуйста, код (наследование)
Начало » Центр помощи » Проверьте, пожалуйста, код (наследование)
1
BlackRabbit
Решаю задачки на codeacademy на наследование классов.
Вроде, все верно, но сайт говорит: “Oops, try again. my_car does not appear to be an instance of ElectricCar”. В чем ошибка?

сlass 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’ + ‘ ’ + self.color + ‘ ’ + self.model + ‘ ’ + ‘with’ + ‘ ’ + str(self.mpg) + ‘ ’ + ‘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, battery_type, model, color, mpg):
self.battery_type = buttery_type
self.model = model
self.color = color
self.mpg = mpg
my_car = ElectricCar('moltensalt', ‘Ecar’, ‘red’, 88)
terabayt
ссылку на задачу?
JOHN_16
BlackRabbit
нулевая ошибка в том что вы отписав более 20 сообщений так и не научились пользоваться тегами code
BlackRabbit
Вот ссылка на задачу: http://www.codecademy.com/ru/courses/python-intermediate-en-egNXj/1/3?curriculum_id=4f89dab3d788890003000096

Условие такое:
Create a class ElectricCar that inherits from Car. Give your new class an __init__() method of that includes a “battery_type” member variable in addition to the model, color and mpg.

Then, create an electric car named “my_car” with a “molten salt” battery_type. Supply values of your choice for the other three inputs (model, color and mpg).

Код прикрепляю.
PanovSergey
class Car(object):
    def __init__(self, model="123", color="123", mpg='123'):
        self.model = model
        self.color = color
        self.mpg = mpg
class ElectricCar(Car):
    def __init__(self, *args, **kwargs):
        
        self.battery_type = kwargs.pop("battery_type")
        super(ElectricCar, self).__init__(*args, **kwargs)
        
my_car = ElectricCar(battery_type="molten salt")
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB