forked from varisha-025/TCS-XPLORE-PYTHON-CODES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item_Store.py
51 lines (51 loc) · 1.44 KB
/
Item_Store.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
class Item:
def __init__(self,name,ptype,price):
self.name=name
self.ptype=ptype
self.price=price
class Store:
def __init__(self,productList):
self.productList=productList
def purchase(self,n_given,qnty_given):
bill=0
for i,qnty in productList.items():
if i.name.lower().strip()==n_given.lower().strip():
if qnty==0:
return None
elif qnty_given>qnty:
bill=i.price*qnty
productList[i]=0
return bill
elif qnty_given<=qnty:
bill=i.price*qnty_given
productList[i]=productList[i]-qnty_given
return bill
return None
if __name__=='__main__':
n=int(input())
productList=[]
for i in range(n):
name=input()
ptype=input()
price=int(input())
qnty=int(input())
ob1=Item(name,ptype,price)
productList.append([ob1,qnty])
productList=dict(productList)
ob2=Store(productList)
num=int(input())
order=[]
for k in range(num):
n_given=input()
qnty_given=int(input())
order.append([n_given,qnty_given])
order=dict(order)
for k,q in order.items():
s=ob2.purchase(k,q)
if s==None:
print(k.lower().strip(),'is not available')
else:
print('Bill of the item',k.lower().strip(),'=',s)
print('Stock in Hand:')
for i in productList:
print(i.name.strip(),productList[i])