-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCATopalian_Python_Vehicle_Class.py
More file actions
84 lines (61 loc) · 1.54 KB
/
CATopalian_Python_Vehicle_Class.py
File metadata and controls
84 lines (61 loc) · 1.54 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# CATopalian_Python_Vehicle_Class.py
# vehicle data list
vehicle_data = [
{
'name': 'RoadRunner',
'power': 'Turbo Boost',
'hp': 170,
'type': 'Car'
},
{
'name': 'IronHauler',
'power': 'Heavy Pull',
'hp': 250,
'type': 'Truck'
}
]
####
# find by name (case insensitive)
def fibn(array, name):
for item in array:
if item['name'].lower() == name.lower():
return item
return None
####
class Vehicle:
def __init__(self, info):
# info has name, power, hp, type
self.name = info['name']
self.power = info['power']
self.hp = info['hp']
self.type = info['type']
def identify(self):
print('this is ' + self.name)
def use_power(self):
print(self.name + ' activated ' + self.power)
####
class Car(Vehicle):
def __init__(self, info):
super().__init__(info)
def drift(self):
print(self.name + ' performed a drift!')
####
class Truck(Vehicle):
def __init__(self, info):
super().__init__(info)
def haul(self):
print(self.name + ' hauled a heavy load!')
####
roadrunner_info = fibn(vehicle_data, 'RoadRunner')
roadrunner = Car(roadrunner_info)
roadrunner.drift()
####
"""
RoadRunner performed a drift!
"""
####
# Dedicated to God the Father
# All Rights Reserved Christopher Andrew Topalian Copyright 2000-2025
# https://github.com/ChristopherTopalian
# https://github.com/ChristopherAndrewTopalian
# https://sites.google.com/view/CollegeOfScripting