Question #317362

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


Expert's answer

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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS