-
Notifications
You must be signed in to change notification settings - Fork 0
/
#OOPR-Prac-1
46 lines (44 loc) · 1.63 KB
/
#OOPR-Prac-1
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
class Purchase:
list_of_items=['Apple', 'Biscuits', 'Chocolates', 'Jam', 'Butter', 'Milk', 'Soap', 'Hand Sanitizer']
list_of_count_of_each_item_sold=[0]*len(list_of_items)
def __init__(self):
self.__items_purchased=[]
self.__item_on_offer=None
def get_items_purchased(self):
return self.__items_purchased
def get_item_on_offer(self):
return self.__item_on_offer
def sell_items(self,list_of_items_to_be_purchased):
count=0
for i in list_of_items_to_be_purchased:
for j in range(0,len(Purchase.list_of_items)):
if i.lower()==Purchase.list_of_items[j].lower():
count+=1
Purchase.list_of_count_of_each_item_sold[j]=count
count=0
self.__items_purchased.append(i.lower())
if i.lower()=="soap":
self.provide_offer()
break
def provide_offer(self):
self.__item_on_offer="HAND SANITIZER"
count=0
for i in range(0,len(Purchase.list_of_items)):
if "hand sanitizer" == Purchase.list_of_items[i].lower():
count+=1
Purchase.list_of_count_of_each_item_sold[i]=count
count=0
@staticmethod
def find_total_items_sold():
sum=0
for i in Purchase.list_of_count_of_each_item_sold:
sum+=i
return sum
s= Purchase()
s.sell_items(['JAM', 'CHOcolates', 'Ghee', 'Soap'])
x=s.get_items_purchased()
print(x)
x=s.get_item_on_offer()
print(x)
x=Purchase.find_total_items_sold()
print(x)