Part of the series

Several example codes

~1 min read • Updated Sep 30, 2025

Program Overview

This Python program calculates how many digital books can be stored on a flash drive.
Each book is assumed to have:
- 30 lines per page
- 40 bytes per line
The user enters:
- Number of pages per book
- Flash drive capacity in gigabytes
The program then calculates how many such books fit into the flash drive.


Python Code:


# Constants
BYTES_PER_LINE = 40
LINES_PER_PAGE = 30
BYTES_PER_PAGE = BYTES_PER_LINE * LINES_PER_PAGE
BYTES_PER_GB = 1024 ** 3  # 1 GB = 1024^3 bytes

# User input
pages_per_book = int(input("Enter number of pages per book: "))
flash_capacity_gb = float(input("Enter flash drive capacity (GB): "))

# Calculations
book_size_bytes = pages_per_book * BYTES_PER_PAGE
flash_capacity_bytes = flash_capacity_gb * BYTES_PER_GB
num_books = flash_capacity_bytes // book_size_bytes

# Display result
print("\n--- Result ---")
print(f"Each book uses {book_size_bytes} bytes")
print(f"Flash drive can store {int(num_books)} books")

Sample Output:


Enter number of pages per book: 100  
Enter flash drive capacity (GB): 2  

--- Result ---  
Each book uses 120000 bytes  
Flash drive can store 17476 books

Explanation:

- Each page uses 30 × 40 = 1200 bytes
- Total book size = pages × 1200
- Flash capacity is converted to bytes using 1024³
- Integer division gives the number of full books that fit


Written & researched by Dr. Shahin Siami