-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotorBike.py
More file actions
44 lines (32 loc) · 865 Bytes
/
MotorBike.py
File metadata and controls
44 lines (32 loc) · 865 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
29
30
31
32
33
34
35
36
37
38
39
40
41
#Class
class MotorBike:
def __init__(self, speed):
self.speed = speed #State
# Behavior
def increase_speed(self, how_much):
self.speed += how_much
# Behavior
def decrease_speed(self, how_much):
if(self.speed - how_much > 0):
self.speed -= how_much
else:
print('Thats Not Gonna Work')
#instance 1 or object 1
honda = MotorBike(50)
#instance 2 or object 2
ducati = MotorBike(250)
#print(honda)
#print(ducati)
#State changes through behavior of the object
honda.increase_speed(150)
ducati.increase_speed(125)
#State changes through behavior of the object
honda.decrease_speed(50)
ducati.decrease_speed(25)
#State changes through behavior of the object
honda.decrease_speed(300)
print(honda.speed)
print(ducati.speed)
#honda.speed = 150
#print(honda.speed)
#print(ducati.speed)