-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog3b_dictionary.py
69 lines (61 loc) · 2.08 KB
/
prog3b_dictionary.py
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
class Employee:
def __init__(self, name, address, pan, basic, tds, deduct, hra, da):
self.name = name
self.address = address
self.pan = pan
self.basic = basic
self.tds = tds
self.deduct = deduct
self.hra = hra
self.da = da
def get_gross_pay(self):
return self.basic + self.da
def get_net_pay(self):
return self.get_gross_pay() - self.deduct
@classmethod
def get_obj_by_prompt(cls):
name = input("Enter name: ")
address = input("Enter address: ")
pan = input("Enter pan: ")
basic = int(input("Enter basic (int): "))
tds = int(input("Enter tds (int): "))
deduct = int(input("Enter deductions (int): "))
hra = int(input("Enter hra (int): "))
da = int(input("Enter da (int): "))
emp = cls(name, address, pan, basic, tds, deduct, hra, da)
return emp
def get_dict(self):
dct = {
"name": self.name,
"address": self.address,
"pan": self.pan,
"basic": self.basic,
"tds": self.tds,
"deduct": self.deduct,
"hra": self.hra,
"da": self.da,
}
return dct
emp_lst = []
while(True):
count = len(emp_lst) + 1
option = input(f"\n\nDo you wish to add Employee {count} (y/n): ")
if option == "n":
break
elif option == "y":
emp = Employee.get_obj_by_prompt()
emp_lst.append(emp)
print(f"\nEmployee {count} created")
else:
print("Invalid input")
if len(emp_lst) > 0:
print("\n\nDisplaying Employee Details")
print("--------------------------------------------------------")
for emp in emp_lst:
dct = emp.get_dict()
print("Employee Details:", dct)
print(f"\nThe gross salary of {emp.name} is {emp.get_gross_pay()}")
print(f"The net salary of {emp.name} is {emp.get_net_pay()}")
print("--------------------------------------------------------")
else:
print("No Employees added")