Booklet Layout

Source: May 2024, Task 2 (DTU 02002/02003). Study solution — not an official answer key.

Problem

Booklet page counts are always multiples of 4. Given content_pages, find the smallest booklet that fits and how many blank pages are needed (0–3).

Write booklet_layout(content_pages) returning (total_pages, blank_pages).

Example
>>> booklet_layout(17)
(20, 3)

Approach

Blank pages needed are (4 - content_pages % 4) % 4. Total is content plus blanks.

Solution

Show solution Hide solution
Solution
def booklet_layout(content_pages):
    blank = (4 - content_pages % 4) % 4
    total = content_pages + blank
    return (total, blank)