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
# 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()
Comments
Leave a comment