AI-Assisted Coding Lab · Paginate Search Results

30:00left of 30:00

Paginate Search Results

The search page needs to show results a page at a time. The README has the rules, and pagination.py has the Page type and the outline of paginate. Build it with the assistant: accept, edit, or reject each suggestion, and keep the tests green.

pagination.py1 of 3

Files

pagination.py

Python · Editable
from dataclasses import dataclass
@dataclass
class Page:
items: list
number: int
total_pages: int
def paginate(results, page, per_page=10):
"""Returns one page of results. Pages are numbered from 1."""
total_pages = page_count(len(results), per_page)
raise NotImplementedError
return Page(items, page, total_pages)
def page_count(total, per_page):
"""How many pages it takes to show total results, per_page at a time."""
raise NotImplementedError

Test Output

No runs yet.

Assistant

Scripted
  1. Send the first prompt to start.

Next Prompt

Write page_count. A partial last page still counts as a page.