-
Notifications
You must be signed in to change notification settings - Fork 14
/
9_May_2022_Painting.py
62 lines (55 loc) · 1.77 KB
/
9_May_2022_Painting.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
class Painting:
def __init__(self, paintingId, painterName, paintingPrice, paintingType):
self.paintingId = paintingId
self.painterName = painterName
self.paintingPrice = paintingPrice
self.paintingType = paintingType
class Showroom:
def __init__(self, paintingObj):
self.paintingList = paintingObj
def getTotalPaintingPrice(self, type):
su = 0
isFound = False
for obj in self.paintingList:
if obj.paintingType.lower() == type.lower():
su = su + obj.paintingPrice
isFound = True
if isFound:
return su
else:
return "No painting found"
def getPainterWithMaxCountOfPaintings(self):
dic = {}
for obj in self.paintingList:
if obj.painterName not in dic:
dic[obj.painterName] = 1
else:
dic[obj.painterName] = dic[obj.painterName] + 1
dic1 = dict(sorted(dic.items(), key = lambda item:item[1], reverse=True))
print(dic1)
lis = []
for k,v in dic1.items():
if len(lis) == 0:
lis.append(k)
temp = v
else:
if temp == v:
lis.append(k)
else:
break
lis.sort()
return lis[0]
paintingObj = []
for i in range(int(input())):
paintingId = int(input())
painterName = input()
paintingPrice = int(input())
paintingType = input()
paintingObj.append(Painting(paintingId,painterName,paintingPrice,paintingType))
obj = Showroom(paintingObj)
type = input()
totalPrice = obj.getTotalPaintingPrice(type)
painter = obj.getPainterWithMaxCountOfPaintings()
# painter.sort()
print(totalPrice)
print(painter)