there multiple(t) book stores in the area. each bookkeeper has a list of b integers that represents the cost of each book. you have different pocket money(p) for each bookstore. write program to calculate the maximum number of books you can buy in each store with the corresponding pocket money. in python
def bookprice(b , N, p):
count = 0
sum = 0
b.sort(reverse = False)
for i in range(0, N, 1):
if (sum+b[i] <= p):
sum = sum + b[i]
count += 1
return count
p = 70
b = [35,32,23]
N = len(b)
print(bookprice(b, N, p))
Comments
Leave a comment