Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, December 3, 2012

Codecademy: Inheritance


#sample solution


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

def driveCar(self):
self.condition = "used"

class ElectricCar(Car):
def __init__(self, model, color, mpg, typeOfBattery):
self.model = model
self.color = color
self.mpg = mpg
self.typeOfBattery = typeOfBattery

myCar = ElectricCar("DeLorean", "silver", 88, "molten salt")

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts