Answer to Question #317362 in Python for Rajesh

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


1
Expert's answer
2022-03-24T07:49:32-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS