-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.py
96 lines (91 loc) · 2.34 KB
/
person.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
90
91
92
93
94
95
96
insensitive = lambda inp:inp.lower()
class Person:
def __init__(self,name,height,weight):
self.name = name
self.height = height
self.weight = weight
self.bmi = 0
self.bmi_status = ""
def calculateBmi(self):
self.bmi = round(self.weight/(self.height*self.height))
class Society:
def __init__(self,bmi_status,person_list):
self.bmi_status = bmi_status
self.person_list = person_list
def getStatus(self,bmi):
for status,bmi_limit in self.bmi_status.items():
low , high = sorted(bmi_limit)
if low<=bmi and bmi<=high:
return status
return ""
def calculateBmiAndStatusByName(self,name):
updatePersons = []
anyUpdate = 0
for person in self.person_list:
if person.name == name:
person.calculateBmi()
person.bmi_status = self.getStatus(person.bmi)
updatePersons.append(person)
anyUpdate = 1
if anyUpdate:
return True , updatePersons
return False
def removeInvalidPersons(self,checkbmi):
filterPersons = []
for person in self.person_list:
person.calculateBmi()
if person.bmi < checkbmi:
filterPersons.append(person)
return filterPersons
if __name__ == '__main__':
nperson = int(input())
personList = [Person(insensitive(input()),int(input()),int(input())) for _ in range(nperson)]
nbmis = int(input())
dictbmiStatus = {}
for _ in range(nbmis):
key = input()
value1 = int(input())
value2 = int(input())
dictbmiStatus[key] = (value1,value2)
socitey = Society(dictbmiStatus,personList)
check , updatePersons = socitey.calculateBmiAndStatusByName(insensitive(input()))
filterPersons = socitey.removeInvalidPersons(int(input()))
print()
for per in updatePersons:
print(f'{per.bmi} {per.bmi_status}')
if not check :
print("No Person Exists")
for person in filterPersons:
print(f'{person.name} {person.bmi}')
# Sample Input
# 5
# Rajesh
# 5
# 50
# Suman
# 4
# 89
# Gopi
# 5
# 99
# Radhika
# 6
# 120
# Rajesh
# 5
# 120
# 4
# Normal
# 2
# 3
# Over Weight
# 4
# 6
# under weight
# 0
# 1
# Abnormal
# 7
# 10
# Rajesh
# 5