──────────────────────────────────────

10. Measure and Plan with Numbers · Show the Right Precision

Calculate a share and display it to a fixed number of decimal places.

Lesson files · lessons/numeric-tools/show-decimal-places

Before you start
- Read a decimal with float(input()).
- Put a result in an f-string.

By the end
- Use division to calculate equal shares.
- Use :.2f in an f-string to show two decimal places.
- Explain what happens to the stored value when you format its display.

Where you can use it
Split juice among several cups and print an easy-to-read label. Keep the full amount per cup if you need it again for a bigger batch.

Use / to divide a quantity among equal shares. With 1.25 litres and four trays, each tray gets 1.25 / 4, which gives 0.3125 litres.

In an f-string, {distance_m:.2f} displays distance_m rounded to two decimal places. It adds zeroes when needed, so 1.0 displays as 1.00. The stored value stays the same. Use that value for any later calculations and format it when you print.

Predict
What does the second print display?
- 1.18 m
- 1.19 m

Worked example (example.py)

distance_m = 1.1875
print(distance_m)
print(f"{distance_m:.2f} m")


Example result
1.1875
1.19 m

Read the total litres on the first line and a positive whole number of seed trays on the second. Divide the water evenly and print the amount for each tray to two decimal places. Enter 1.25 and 4 to get 0.31 L per tray.

Starter program (starter.py)

total_litres = float(input())
trays = int(input())
print(f"{total_litres} L to share")


Starter input
1.25
4

Hint
Divide the litres by the tray count. Put :.2f after the name of the result inside the braces of your f-string.

Case 1. Try the sample
Input
1.25
4
Expected output
0.31 L per tray

Case 2. One litre each
Input
2
2
Expected output
1.00 L per tray

Case 3. No water to share
Input
0
3
Expected output
0.00 L per tray

Stretch
For the sample input, also show the amount in millilitres per tray to one decimal place. Convert the stored share and compare it with a conversion of the displayed 0.31 L.

Reflect
Where would you make the label show three decimal places?

Check your prediction
1.19 m To display two decimal places, Python rounds 1.1875 to 1.19.
