8000 Updated answers for 4 · zfoxpython/intro-to-python@7564638 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7564638

Browse files
committed
Updated answers for 4
1 parent 225e406 commit 7564638

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

session_10/answers/A4.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11

2-
# 4. Create a Employee class and initialise it with name and staff number. Make methods to:
3-
# - display_info - It should display all the information of the employee.
4-
# - set_department - It should assign the department to employee.
5-
# - set_bonus - It should assign a bonus amount to the employee.
2+
# 3. Create a Vehicle parent class, initialise it with, wheels, colour and a method to display all this information.
3+
# - i. Create a Tesla (or any car brand) child classs and add a method to get the miles and a method to display all this information.
4+
# - ii. Change the colour of the vehicle.
5+
# - iii. Delete the wheels.
6+
7+
class Vehicle:
8+
def __init__(self, wheels, colour):
9+
self.wheels = wheels
10+
self.colour = colour
11+
12+
def display_info(self):
13+
print("This car is " + self.colour + " and has " + str(self.wheels) + " wheels.")
14+
15+
class Tesla(Vehicle):
16+
def __init__(self, wheels, colour, miles):
17+
super().__init__(wheels, colour)
18+
self.miles = miles
19+
20+
def display_more_info(self):
21+
print("This car is " + self.colour + " and has " + str(self.wheels) + " wheels and " + str(self.miles) + " miles.")
22+
23+
tesla = Tesla(4, "black", 20000)
24+
tesla.display_more_info()
25+
26+
tesla.colour = "red"
27+
tesla.display_more_info()
28+
29+
del tesla.wheels
30+
tesla.display_more_info()
31+
32+
33+

0 commit comments

Comments
 (0)
0