forked from iabhigupta/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarClassDemo.py
More file actions
28 lines (26 loc) · 809 Bytes
/
CarClassDemo.py
File metadata and controls
28 lines (26 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Car(object):
condition = "new"
def __init__(self, model, color, mpg):
self.model = model
self.color = color
self.mpg = mpg
def display_car(self):
print "This is a %s %s with %s MPG."%(self.color, self.model, self.mpg)
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
print my_car.model
print my_car.color
print my_car.mpg
my_car.display_car
class ElectricCar(Car):
def __init__(self, battery_type, model, color, mpg):
self.battery_type = battery_type
self.model = model
self.color = color
self.mpg = mpg
def drive_car(self):
self.condition = "like new"
return self.condition
my_car = ElectricCar( "molten salt","Luxury", "blue", 120)
print my_car.drive_car()
print my_car.condition