LessonΒ·difficulty 1/5Β·~7 min
Share the cookies
When you split things into equal groups, two questions come up: how many does each group get? and how many are left over? Python has one operator for each:
//β whole-number divide (how many fit in each group)%β the remainder (what's left over)
python
print(17 // 5) # 3
print(17 % 5) # 2
Your task
You have 17 cookies to share equally among 5 friends.
eachβ how many whole cookies each friend gets. Which operator splits into equal whole groups?leftoverβ how many cookies don't fit into a full group. Which operator gives the remainder?
You've seen // and % in action above β now use them on cookies and
friends to fill in each and leftover yourself, then print(each, leftover).
Sanity check:
each * friends + leftovershould add right back up tocookies. That identity is true for any numbers you plug in.
Tests
- each friend gets 3 whole cookies
- 2 cookies are left over
β¦ 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.