CP1 / COURSE HOME

Week 02 / Describe and decide

Report a measurement clearly

Turn a numeric result into a useful message.

Last week we attached meaning and units to a number. Now someone else has to read it. A useful report must preserve the information needed for a decision.

An inspection station measures two shafts: 10.049 mm and 10.051 mm. The permitted band is 9.95–10.05 mm, including both limits.

Start with the problem

Try this first.

Both measurements can appear as “10 mm” on a whole-millimetre display. Decide which shaft is within the band, then sketch a display that makes the difference visible.

Why this week's tool?

Type conversion makes incoming text usable as a number. F-strings let us choose how to present it while keeping the original value for calculations.

By the end: Show a readable measurement message without letting display rounding change the inspection result.

The idea behind the program

Conversion is a decision

Input text such as '10.049' must become a numeric value before arithmetic. int() truncates a float toward zero; it is not a general rounding instruction. Keep the original text when you need to trace where a value came from.

Separate calculation from presentation

An f-string such as f'{diameter_mm:.1f}' formats a display. It should not replace the measurement used for acceptance. In this lesson, compare the unrounded value with the stated inclusive limits. We will implement the decision branch next week.

A tolerance is not measurement uncertainty

The acceptance band is a design requirement. Sensor uncertainty describes what you know about the measurement. Our prepared cases assume exact input values to isolate the display problem; a real measurement near a limit needs an agreed uncertainty policy.

A short Python example

Read the example alongside the explanation. Run it in a new notebook cell and change one input to see how it behaves.

diameter_text = '10.049'
diameter_mm = float(diameter_text)
print(f'Display: {diameter_mm:.1f} mm')
print(f'Inspection record: {diameter_mm:.3f} mm')
print('Within stated band:', 9.95 <= diameter_mm <= 10.05)

Example output

Display: 10.0 mm
Inspection record: 10.049 mm
Within stated band: True

Representation is not the quantity itself

Text, a numeric value and formatted output are different representations. Conversion makes arithmetic possible; formatting makes a result readable. Neither operation establishes that a measurement is valid.

Draw or trace

Draw a pipeline: input text → numeric value → decision → display. Attach millimetres to the value in your explanation; Python does not infer that unit from the variable name.

Predict before running. The limit is 10.05 mm, inclusive. Should a reading of 10.051 pass because a two-decimal display shows 10.05?

Trace and explanation — after your prediction
  1. The text "10.051" becomes the number 10.051.
  2. Compare the unrounded value with 10.05: it exceeds the limit.
  3. A formatted display can show 10.05 without changing the stored value.

It fails this exact-value teaching rule. Rounding the display must not silently change the decision. A real inspection policy may also need measurement uncertainty, which is separate from formatting.

Change one thing. Compare "12" + "3" with 12 + 3. Explain why the same symbol can concatenate text or add numbers.

Türkçe: Metin, sayı ve biçimlendirilmiş çıktı farklıdır. Gösterimde yuvarlama, karar için kullanılan değeri sessizce değiştirmemelidir.

Examples and variations

Each example changes something about the same problem. Open the ones you want to explore and follow the worked explanation.

01Inside the band

10.049 mm; band 9.95–10.05 mm inclusive

Question: What does the one-decimal display show, and is the raw value within the band?

  1. Parse text as float: 10.049
  2. Format to one decimal: 10.0
  3. 9.95 ≤ 10.049 ≤ 10.05

Display 10.0 mm; within band

Formatting is useful for readability, but the inspection record needs more detail.

02Just below the band

9.949 mm; same acceptance band

Question: Could the display conceal a rejection?

  1. Format 9.949 to one decimal: 9.9
  2. 9.949 < 9.95
  3. The unrounded value is outside the band

Display 9.9 mm; outside band

Always inspect the raw comparison. Do not infer a decision from the number of displayed decimals.

03Coarse display collision

10.049 mm and 10.051 mm; whole-millimetre display

Question: Do identical displays imply identical decisions?

  1. Both formatted with .0f produce 10
  2. 10.049 is within the band
  3. 10.051 exceeds 10.05

Both display 10 mm; only one is within band

The display discards information. Preserve the original numeric value and include an explicit acceptance message.

See the Colab code run

Interactive walkthroughs of Operators, F-Strings & Type Conversion. Enable JavaScript to step through code, variables, collections and output. The companion notebook remains available below.

Work on it in Colab

Use the notebook to try the ideas yourself. The steps below connect this week's example to the programming practice.

  1. Draw an operator display and a separate inspection record. Decide which needs the raw value, units, precision and acceptance message.
  2. Run the model for 10.049 and 10.051. Try .0f, .1f and .3f without changing the decision expression.
  3. Replace the measurement with int(diameter_mm). Predict and explain the loss of fractional information.
  4. Test exactly 9.95 and 10.05. Write the inclusive-band rule in plain language before showing the output.

Something to take away: A small table of raw values, displays and decisions, plus a proposed display that does not hide the acceptance result.

Suggested exercises, downloads & solutions

Read the notebook's teaching cells before these exercises.

  • EX01 Operator Predictions (Easy)
  • EX02 Type Conversion Traps (Easy)
  • EX07 Temperature Table (Medium)
Download notebookWorked solutions

Use the notebook's core and optional labels to choose your workload. This activity fits within guided class time.

Optional notes & guidance
My notes
Using AI or working with a partner

Ask AI for a neat inspection display. Check whether it rounds before deciding. Give it 10.051 mm and require the rejection to survive formatting. Reject explanations that confuse tolerance with sensor accuracy.

You can also review the supplied example with a partner. Use the same inputs to compare the reasoning. Follow the syllabus rules for assessed work.