Answer to Question #292133 in Python for Aparna

Question #292133

there are multiple (T) bookstores in the area. Each shopkeeper has a list of B integers that represent the cost of each book.You have different pocket money P for each bookstore. Write a program to calculate the maximum number of books you can buy in each bookstore with the corresponding pocket money


1
Expert's answer
2022-01-30T10:38:30-0500
# Python 3.9.5


def get_count_book(book, money):
    count_book = 0
    for i in book:
        money -= i
        if money >= 0:
            count_book += 1
    print(count_book)


def main():
    list_book1 = [1, 1, 3, 4, 5, 7]
    pook_money1 = 6
    list_book2 = [1, 2, 3, 5, 5, 7]
    pook_money2 = 11
    get_count_book(list_book2, pook_money2)


if __name__ == '__main__':
    main()

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