import string
#Implement/Define Store class
class Vegetable:
def __init__(self, name, price, quantity):
self.name = name
self.price = price
self.quantity = quantity
#Implement/Define Store class
class Store:
def __init__(self, storeName, vegList):
self.storeName = storeName
self.vegList = vegList
def categorizeVegetablesAlphabetically(self):
self.vegList.sort(key= lambda x: x.name)
alpha = list(string.ascii_lowercase)
ret = {}
for i in alpha:
temp = []
for j in self.vegList:
if i == j.name[0]:
temp.append(j.name)
if len(temp) >0:
ret[i] = tuple(temp)
return ret
def filterVegetablesForPriceRange(self, minimum, maximum):
self.vegList.sort(key= lambda x: x.name)
ret = []
for i in self.vegList:
if minimum <= i.price <= maximum:
ret.append(i.name)
return ret
#Implement main function , Refer the Instructions in Qn text , which helps you to write main #function"
num = int(input())
temp = []
for i in range(num):
name = input()
price = float(input())
quantity = int(input())
veg = Vegetable(name.lower(),price,quantity)
temp.append(veg)
name = input()
a = float(input())
b = float(input())
store = Store(name,temp)
catVegAlpha = store.categorizeVegetablesAlphabetically()
priceList = store.filterVegetablesForPriceRange(a, b)
for keys, value in catVegAlpha.items():
print(keys)
for x in value:
print(x)
print(str(a) + '-' + str(b))
if len(priceList) > 0:
for x in priceList:
print(x)
else:
print("No Vegetable(s) in the given price range")
No comments:
Post a Comment