LessonΒ·difficulty 2/5Β·~15 min
Paginate an inventory
Implement paginate(items, page, size).
page and size are integers. Pages start at 1. Return that page as a new list. Return [] beyond the end. Raise ValueError for page < 1 or size < 1. Keep items unchanged.
Before coding, predict one result by hand. After the tests pass, explain your approach and add a boundary example of your own.
Tests
- Case 1
- Case 2
- Case 3
- Case 4
- Reject page=0, size=2
- Reject page=1, size=0
- Reject page=-1, size=2
- Reject page=1, size=-1
β¦ Stuck? Ask for a spark
Sign in or create a free account to use your monthly AI explainer allowance.
warming up
Loading editorβ¦
Consolewaiting
$ Console output will appear here.