-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses_task.py
More file actions
98 lines (82 loc) · 2.38 KB
/
classes_task.py
File metadata and controls
98 lines (82 loc) · 2.38 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import datetime
class employee:
def __init__(self, name, age, salary, empDate):
self.name = name
self.age = age
self.salary = salary
self.empDate = empDate
def __str__(self):
return ("Name: %s, Age: %d, Salary: %d, Working years: %d"
%(self.name,self.age,self.salary,self.get_working_years(self.empDate) ))
def get_working_years(self, year):
today = int(datetime.datetime.now().year)
return (today - year)
class manager(employee):
def __init__(self, name, age, salary, empDate, bonus_percentage):
super().__init__(name, age, salary, empDate)
self.bonus_percentage = bonus_percentage
def __str__(self):
return ("Name: %s, Age: %d, Salary: %d, Working years: %d, Bonus: %.3f\n"
%(self.name,self.age,self.salary,self.get_working_years(self.empDate),
(self.bonus_percentage*self.salary) ))
def get_bonus(self):
return bonus_percentage * salary
welcome = "Welcome to HR Pro 2019"
menu = """Choose an action to do:
1. show employees
2. show managers
3. add an employee
4. add a manager
5. exit
"""
employees_list = []
managers_list = []
def print_employees():
print ("-----------------\n")
for x in employees_list:
print (x)
print ("-----------------\n")
def print_managers():
print ("-----------------\n")
for x in managers_list:
print (x)
print ("-----------------\n")
def add_employee():
print ("-----------------\n")
name = input("Name: ")
age = int(input("Age: "))
salary = int(input("Salary: "))
empDate = int(input("Employment year: "))
print ("\nProcessing...")
new_employee = employee(name, age, salary, empDate)
employees_list.append(new_employee)
print ("Employee added successfully.")
print ("-----------------\n")
def add_manager():
print ("-----------------\n")
name = input("Name: ")
age = int(input("Age: "))
salary = int(input("Salary: "))
empDate = int(input("Employment year: "))
bonus_percentage = float(input("Bonus %: "))
print ("\nProcessing...")
new_manager = manager(name, age, salary, empDate, bonus_percentage)
managers_list.append(new_manager)
print ("Manager added successfully.")
print ("-----------------\n")
print (welcome)
userVar = 0
while userVar != 5:
userVar = int(input(menu))
if userVar == 1:
print_employees()
elif userVar == 2:
print_managers()
elif userVar == 3:
add_employee()
elif userVar == 4:
add_manager()
elif userVar > 5:
print ("Please input a correct command. \n")
else:
exit(1)