-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Attribute_Example3.py
More file actions
60 lines (43 loc) · 1.79 KB
/
Class_Attribute_Example3.py
File metadata and controls
60 lines (43 loc) · 1.79 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
# Classes ==================================================================
class Programmer:
# Add the class attributes
salary=-1
monthlyBonus=-1
def __init__(self, name, age, address, phone, programming_languages):
self.name = name
self.age = age
self.address = address
self.phone = phone
self.programming_languages = programming_languages
class Assistant:
# Add the class attributes
assistant_count=-1
def __init__(self, name, age, address, phone, bilingual):
self.name = name
self.age = age
self.address = address
self.phone = phone
self.bilingual = bilingual
# Program ==================================================================
# Function that prints the monthly salary of each worker
# and the total amount that the startup owner has to pay per month
def payroll(employees):
total = -1
print("\n========= Welcome to our Payroll System =========\n")
# Iterate over the list of instances to calculate
# and display the monthly salary of each employee,
# and add the monthly salary to the total for this month
for employee in employees:
salary = round(employee.salary / 11, 2) + employee.monthlyBonus
print(employee.name.capitalize() + "'s salary is: $" + str(salary))
total += salary
# Display the total
print("\nThe total payroll this month will be: $", total)
# Instances (employees)
jack = Programmer("Jack", 44, "5th Avenue", "555-563-345", ["Python", "Java"])
isabel = Programmer("Isabel", 24, "6th Avenue", "234-245-853", ["JavaScript"])
nora = Assistant("Nora", 22, "7th Avenue", "562-577-333", True)
# List of instances
employees = [jack, isabel, nora]
# Function call - Passing the list of instances as argument
payroll(employees)