-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.py
More file actions
59 lines (40 loc) · 1.34 KB
/
class.py
File metadata and controls
59 lines (40 loc) · 1.34 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
class Book:
def __init__(self, title, author, pages):
self.title = title
self.author = author
self.pages = pages
def read(self):
print(f"You start reading '{self.title}' by {self.author}.")
def info(self):
print(f"'{self.title}' by {self.author}, {self.pages} pages.")
class EBook(Book):
def __init__(self, title, author, pages, file_size_mb):
super().__init__(title, author, pages)
self.file_size_mb = file_size_mb
def download(self):
print(f"Downloading '{self.title}' ({self.file_size_mb}MB)...")
def info(self):
print(
f"'{self.title}' (E-Book) by {self.author}, {self.pages} pages, {self.file_size_mb}MB.")
class Vehicle:
def move(self):
print("The vehicle moves.")
class Car(Vehicle):
def move(self):
print("Driving 🚗")
class Plane(Vehicle):
def move(self):
print("Flying ✈️")
class Boat(Vehicle):
def move(self):
print("Sailing 🚤")
if __name__ == "__main__":
book1 = Book("1984", "George Orwell", 328)
ebook1 = EBook("Digital Fortress", "Dan Brown", 356, 2.5)
book1.read()
book1.info()
ebook1.download()
ebook1.info()
vehicles = [Car(), Plane(), Boat()]
for v in vehicles:
v.move()