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

Skip to content
8000

Commit 225e406

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

File tree

1 file changed

+51
-27
lines changed

1 file changed

+51
-27
lines changed

session_10/answers/A3.py

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
11

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
2+
# 3. Create a Employee class and initialise it with name and staff number.
3+
# - i. Make methods to:
4+
# - display_info - It should di 10000 splay all the information of the employee.
5+
# - set_department - It should assign the department to employee.
6+
# - set_bonus - It should assign a bonus amount to the employee.
7+
8+
class Employee:
9+
def __init__(self, name, staff_number):
10+
self.name = name
11+
self.staff_number = staff_number
1112

1213
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
14+
print("Employee Information: \n Name: " + self.name + "\n Staff ID: " + str(self.staff_number) + "\n Bonus: " + str(self.bonus) + "\n Department: " + str(self.department))
1915

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-
16+
def set_department(self, department):
17+
self.department = department
18+
19+
def set_bonus(self, bonus):
20+
self.bonus = bonus
21+
22+
employee1 = Employee("Saf Mirza", 23435)
23+
employee1.set_bonus(1000)
24+
employee1.set_department("Technology")
25+
employee1.display_info()
26+
27+
# - ii. Create the instance attributes fullname and email in the Employee class.
28+
# - Given a person's first and last names:
29+
# - Form the fullname by simply joining the first and last name together, separated by a space.
30+
# - Form the email by joining the first and last name together with a . in between, and follow it with @company.com at the end. Make sure everything is in lowercase.
31+
32+
class Employee:
33+
def __init__(self, first_name, last_name, staff_number):
34+
self.first_name = first_name
35+
self.last_name = last_name
36+
self.staff_number = staff_number
37+
38+
def display_info(self):
39+
print(self.first_name, self.last_name, self.staff_number, self.bonus, self.department)
3240

41+
def set_department(self, department):
42+
self.department = department
3343

44+
def set_bonus(self, bonus):
45+
self.bonus = bonus
46+
47+
def full_name(self):
48+
fullname = self.first_name + " " + self.last_name
49+
print("Fullname: " + fullname)
50+
51+
def email_address(self):
52+
email = self.first_name + "." + self.last_name + "@company.com"
53+
print("Email: " + email.lower())
54+
55+
employee1 = Employee("Saf", "Mirza", 23435)
56+
employee1.full_name()
57+
employee1.email_address()

0 commit comments

Comments
 (0)
0