-
Notifications
You must be signed in to change notification settings - Fork 14
/
20_December_2022_Employee.py
89 lines (78 loc) · 2.66 KB
/
20_December_2022_Employee.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class Employee:
def __init__(self,empName,empDesignation, empSalary, loan):
self.empName = empName
self.empDesignation = empDesignation
self.empSalary = empSalary
self.loan = loan
class Organization:
def __init__(self,empObj,loanType,maxDesiganationAmount):
self.empList = empObj
self.loanType = loanType
self.maxDesiganationAmount = maxDesiganationAmount
def eligibleForLoan(self,name,type,amount):
isFound = False
for obj in self.empList:
if obj.empName.lower() == name.lower() and type.lower() not in obj.loan and type.lower() in self.loanType:
su = amount
for _,v in obj.loan.items():
su = su + v
for k,v in self.maxDesiganationAmount.items():
if k == obj.empDesignation.lower():
if su < v:
obj.loan[type] = amount
return obj
else:
return False
if not isFound:
return False
def stillEligibleForLoan(self):
eligible = {}
for obj in self.empList:
su = 0
des = obj.empDesignation
for k,v in obj.loan.items():
su = su + v
if des.lower() in self.maxDesiganationAmount:
if su < self.maxDesiganationAmount[des.lower()]:
if des not in eligible:
eligible[des] = 1
else:
eligible[des] = eligible[des] + 1
else:
eligible[des] = 0
dic1 = dict(sorted(eligible.items(), key=lambda item:item[0], reverse=True))
return dic1
empObj = []
for _ in range(int(input())):
empName = input()
empDesignation = input()
empSalary = int(input())
loan = {}
for i in range(int(input())):
key = input().lower()
value = int(input())
loan[key] = value
empObj.append(Employee(empName,empDesignation,empSalary,loan))
loanType = []
for _ in range(int(input())):
inp = input().lower()
loanType.append(inp)
maxDesiganationAmount = {}
for _ in range(int(input())):
key = input().lower()
value = int(input())
maxDesiganationAmount[key] = value
name = input()
type = input()
amount = int(input())
obj = Organization(empObj,loanType,maxDesiganationAmount)
res = obj.eligibleForLoan(name,type,amount)
if res:
print("Loan Granted.")
for k,v in res.loan.items():
print(k,": ",v)
else:
print("Not Found")
eligible = obj.stillEligibleForLoan()
for k,v in eligible.items():
print(k,": ",v)