← Practice
πŸ“– Numbers and arithmeticshare-the-cookies
LessonΒ·difficulty 1/5Β·~7 min

Share the cookies

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.

  1. each β€” how many whole cookies each friend gets (cookies // friends).
  2. leftover β€” how many cookies are left over (cookies % friends).
python
cookies = 17
friends = 5

each = cookies // friends
leftover = cookies % friends
print(each, leftover)

Sanity check: each * friends + leftover should add right back up to cookies. That identity is true for any numbers you plug in.

Tests

  • each friend gets 3 whole cookies
  • 2 cookies are left over
  • the pieces add back up to all the cookies (hidden)

✦ Stuck? Ask for a spark

warming up
Loading editor…

$ Console output will appear here.

>_AI tutor
Sign in to chat with the tutor.