-
-
Save codecademydev/6308387050c129117e732d6388420dd0 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, self.mpg) | |
def drive_car(self): | |
#self.condition = condition | |
self.condition = "used" | |
class ElectricCar(Car): | |
def __init__(self, model, color, mpg, battery_type): | |
#you have to put in the objects below again | |
super(ElectricCar, self).__init__(model, color, mpg) | |
self.battery_type = battery_type | |
def drive_car(self): | |
self.condition = "like new" | |
my_car = Car("DeLorean", "silver", 88) | |
#my_car = ElectricCar("Tesla", "black", 2017, "molten salt") | |
print my_car | |
print my_car.model | |
print my_car.color | |
print my_car.mpg | |
print my_car.condition | |
my_car.drive_car() | |
print my_car.condition | |
#print my_car.display_car() | |
#To call a method or a function, you need to place parentheses #after its name, even if you are not passing any arguments to #the method or function. YOU 4GOT this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment