-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.5.py
More file actions
72 lines (51 loc) · 1.6 KB
/
11.5.py
File metadata and controls
72 lines (51 loc) · 1.6 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
# Task 1
class Customer(object):
def __init__(self, customer_id):
self.customer_id = customer_id
def display_cart(self):
print("The products in the cart are milk, apple.")
class ReturnedCustomer(Customer):
def display_order_history(self):
print("The history orders are No.234 and No.456")
monty_python = ReturnedCustomer("12345")
monty_python.display_cart()
monty_python.display_order_history()
# Task 2
class Shape(object):
def __init__(self, number_of_sides):
self.number_of_sides = number_of_sides
class Triangle(Shape):
def __init__(self, side1, side2, side3):
self.side1 = side1
self.side2 = side2
self.side3 = side3
tri = Triangle(3, 4, 5)
print(tri)
# Task 3
class Employee(object):
def __init__(self, name):
self.name = name
# other这里代表的是Employee对象或者Boss对象
def greet(self, other):
print("Hello %s" % other.name)
def calculate_wage(self, hours):
self.hour = hours
return 20.00 * hours
class Boss(Employee):
def greet(self, other):
print("Please go back to work, %s" % other.name)
class PartTimeEmployee(Employee):
def calculate_wage(self, hours):
self.hours = hours
return 12.00 * hours
# print("The wage is {}".format(wage))
def full_time_wage(self, hours):
self.hours = hours
return super(PartTimeEmployee, self).calculate_wage(hours)
emp = Employee("Lily")
boss = Boss("Bush")
emp.greet(emp)
emp.greet(boss)
pemp = PartTimeEmployee("Lucy")
print(pemp.calculate_wage(2))
print(pemp.full_time_wage(10))