0% found this document useful (0 votes)
4 views2 pages

Book Borrowing Statistics and Analysis

The document contains a Python script for managing book borrowing by members, tracking the number of books borrowed by each member and the borrow counts for each book. It includes functions to calculate the average number of books borrowed, identify the highest and lowest borrowed books, count members who haven't borrowed any books, and find the most frequently borrowed book. The script also demonstrates its functionality with sample member and book borrowings.

Uploaded by

Tejas Sarangdhar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Book Borrowing Statistics and Analysis

The document contains a Python script for managing book borrowing by members, tracking the number of books borrowed by each member and the borrow counts for each book. It includes functions to calculate the average number of books borrowed, identify the highest and lowest borrowed books, count members who haven't borrowed any books, and find the most frequently borrowed book. The script also demonstrates its functionality with sample member and book borrowings.

Uploaded by

Tejas Sarangdhar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

member_borrow_counts = {}

book_borrow_counts = {}

def borrow_book(member_id, book_title):


if member_id in member_borrow_counts:
member_borrow_counts[member_id] += 1
else:
member_borrow_counts[member_id] = 1

if book_title in book_borrow_counts:
book_borrow_counts[book_title] += 1
else:
book_borrow_counts[book_title] = 1

def average_books_borrowed():
if not member_borrow_counts:
return 0
total = sum(member_borrow_counts.values())
count = len(member_borrow_counts)
return total / count

def highest_and_lowest_borrowed_books():
if not book_borrow_counts:
return None, None
highest = max(book_borrow_counts, key=book_borrow_counts.get)
lowest = min(book_borrow_counts, key=book_borrow_counts.get)
return highest, lowest

def count_zero_borrow_members(all_members):
count = 0
for member_id in all_members:
if member_borrow_counts.get(member_id, 0) == 0:
count += 1
return count

def most_frequently_borrowed_book():
if not book_borrow_counts:
return None
max_count = max(book_borrow_counts.values())
for book, count in book_borrow_counts.items():
if count == max_count:
return book

all_members = ["A", "B", "C", "D", "E"]

borrow_book("A", "Python")
borrow_book("B", "Python")
borrow_book("C", "Java")
borrow_book("B", "Python")
borrow_book("A", "C++")
borrow_book("E", "Java")

print("Average Borrowed books:", average_books_borrowed())


high, low = highest_and_lowest_borrowed_books()
print("Highest borrowed book:", high)
print("Least borrowed book:", low)
print("Members who borrowed 0 books:", count_zero_borrow_members(all_members))
print("Most frequently borrowed book (mode):", most_frequently_borrowed_book())

You might also like