Code

Whole Jars and Leftovers

Sometimes a decimal answer is no good. You can't give an island 3.4 jars of oil! Python has two operators for sharing things out in whole pieces:

Operator Asks Example Result
// how many whole times does it fit? 7 // 2 3
% what is left over? 7 % 2 1

// is called whole-number division (or floor division). % is called the remainder. They make a great team:

cookies = 10
friends = 3
print(cookies // friends)  # 3 each
print(cookies % friends)   # 1 left over

Check it: 3 friends get 3 cookies each. That's 9, plus 1 left over, makes 10.

Assignment

The Guild has 17 jars of lantern oil to share between 5 islands. Use the variables jars and islands, not the numbers:

  1. Set each to how many whole jars each island gets.
  2. Set left_over to how many jars remain.