Skip to content

Commit a90f743

Browse files
committed
lesson 18 added
1 parent 6506adc commit a90f743

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@
7474
- 🔗 [Chapter 15 - Command Line Arguments](https://github.com/gitdagray/python-course/tree/main/lesson15)
7575
- 🔗 [Chapter 16 - Student Challenge](https://github.com/gitdagray/python-course/tree/main/lesson16)
7676
- 🔗 [Chapter 17 - Lambda & Higher Order Functions](https://github.com/gitdagray/python-course/tree/main/lesson17)
77+
- 🔗 [Chapter 18 - Classes, Objects, Inheritance & Polymorphism](https://github.com/gitdagray/python-course/tree/main/lesson18)

lesson18/classes.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class Vehicle:
2+
def __init__(self, make, model):
3+
self.make = make
4+
self.model = model
5+
6+
def moves(self):
7+
print('Moves along..')
8+
9+
def get_make_model(self):
10+
print(f"I'm a {self.make} {self.model}.")
11+
12+
13+
my_car = Vehicle('Tesla', 'Model 3')
14+
15+
# print(my_car.make)
16+
# print(my_car.model)
17+
my_car.get_make_model()
18+
my_car.moves()
19+
20+
your_car = Vehicle('Cadillac', 'Escalade')
21+
your_car.get_make_model()
22+
your_car.moves()
23+
24+
25+
class Airplane(Vehicle):
26+
def __init__(self, make, model, faa_id):
27+
super().__init__(make, model)
28+
self.faa_id = faa_id
29+
30+
def moves(self):
31+
print('Flies along..')
32+
33+
34+
class Truck(Vehicle):
35+
def moves(self):
36+
print('Rumbles along..')
37+
38+
39+
class GolfCart(Vehicle):
40+
pass
41+
42+
43+
cessna = Airplane('Cessna', 'Skyhawk', 'N-12345')
44+
mack = Truck('Mack', 'Pinnacle')
45+
golfwagon = GolfCart('Yamaha', 'GC100')
46+
47+
cessna.get_make_model()
48+
cessna.moves()
49+
mack.get_make_model()
50+
mack.moves()
51+
golfwagon.get_make_model()
52+
golfwagon.moves()
53+
54+
print('\n\n')
55+
56+
for v in (my_car, your_car, cessna, mack, golfwagon):
57+
v.get_make_model()
58+
v.moves()

0 commit comments

Comments
 (0)