Lesson·difficulty 1/5·~7 min
Share the cookies
Read the task → edit your code → Run to see the output → Run tests to check your answer.
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
✦ Need help with this task?
Sign in or create a free account to get AI help. Free includes a monthly AI allowance.
warming up
Loading editor…
Consolewaiting
$ Console output will appear here.