-
Notifications
You must be signed in to change notification settings - Fork 1
/
fruitsOrder.py
62 lines (53 loc) · 1.93 KB
/
fruitsOrder.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 FruitsOrder:
def __init__(self, itemId, fruitName, fruitType, unitQtyOrdered, pricePerUnit):
self.itemId = itemId
self.fruitName = fruitName
self.fruitType = fruitType
self.unitQtyOrdered = unitQtyOrdered
self.pricePerUnit = pricePerUnit
def TotalPrice(self):
return self.unitQtyOrdered*self.pricePerUnit
class FruitsStore:
def __init__(self, fList, avFruitist):
self.fList = fList
self.avFruitist = avFruitist
def getTotalPriceOfAvailableOrderedFruit(self, itemId):
for item in self.fList:
if itemId == item.itemId:
avfruit = item.fruitName+"-"+item.fruitType
if avfruit in self.avFruitist:
return item.TotalPrice()
return None
def getFruitWithLeastPrice(self):
LeastPriceObject = self.fList[0]
for i in range(len(self.fList)):
if self.fList[i].TotalPrice() < LeastPriceObject.TotalPrice():
LeastPriceObject = self.fList[i]
return LeastPriceObject
noOfFruitsOrder = int(input())
FruitsOrderObjects = []
for i in range(noOfFruitsOrder):
itemId = int(input())
fruitName = input()
fruitType = input()
unitQtyOrdered = int(input())
pricePerUnit = float(input())
FruitsOrderObjects.append(FruitsOrder(
itemId, fruitName, fruitType, unitQtyOrdered, pricePerUnit))
noOfAvFruits = int(input())
AvFruitsList = []
for i in range(noOfAvFruits):
avFriuts = input()
AvFruitsList.append(avFriuts)
FruitsStoreobject = FruitsStore(FruitsOrderObjects, AvFruitsList)
itemId = int(input())
totalPrice = FruitsStoreobject.getTotalPriceOfAvailableOrderedFruit(itemId)
LeastPrice = FruitsStoreobject.getFruitWithLeastPrice()
if totalPrice is None:
print("itemID OR fruit not fount")
else:
print(totalPrice)
print(LeastPrice.itemId)
print(LeastPrice.fruitName)
print(LeastPrice.fruitType)
print(LeastPrice.TotalPrice)