Make the numbers work.
Calculate totals, split work, and understand the result you are getting.
01 The idea
Python has integers for whole numbers and floats for approximate decimal values. Arithmetic operators produce new values: + adds, * multiplies, / divides, // performs floor division, % gives a remainder, and ** raises a power. Pick the operation that matches the question.
02 The experiment
Read it once. Predict what will happen. Then copy it into a .py file and run it in your local Python setup.
assets = 17
per_batch = 5
print(assets // per_batch)
print(assets % per_batch)
print(2 ** 4)
print(assets / per_batch)3 2 16 3.4
03 Under the hood
- 1
17 // 5 gives three complete batches. With positive values, floor division tells us how many whole groups fit.
- 2
17 % 5 gives two leftover assets. Together, quotient and remainder describe the split.
- 3
Division with / produces a float here. Floats are approximate: for exact decimal accounting, investigate the decimal module rather than relying on binary floats.
04 Your turn, builder
You have 29 tasks and can finish 6 per day. Print the number of complete groups of 6 and the leftover tasks.
Reveal one possible solution +
tasks = 29
print(tasks // 6)
print(tasks % 6)05 Check your signal
What does 14 % 4 evaluate to?
Experiment. Logged.
When you can explain the idea and make the example your own, mark it complete. Your log stays in this browser.
Keep exploring
Go deeper with the official Python guide ↗.