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.
Week 02 / Describe and decide
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
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.
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.
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.
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.
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.
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)Display: 10.0 mm Inspection record: 10.049 mm Within stated band: True
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 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?
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.
Each example changes something about the same problem. Open the ones you want to explore and follow the worked explanation.
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?
Formatting is useful for readability, but the inspection record needs more detail.
9.949 mm; same acceptance band
Question: Could the display conceal a rejection?
Always inspect the raw comparison. Do not infer a decision from the number of displayed decimals.
10.049 mm and 10.051 mm; whole-millimetre display
Question: Do identical displays imply identical decisions?
The display discards information. Preserve the original numeric value and include an explicit acceptance message.
Interactive walkthroughs of Operators, F-Strings & Type Conversion. Enable JavaScript to step through code, variables, collections and output. The companion notebook remains available below.
Use the notebook to try the ideas yourself. The steps below connect this week's example to the programming practice.
Something to take away: A small table of raw values, displays and decisions, plus a proposed display that does not hide the acceptance result.
Read the notebook's teaching cells before these exercises.
Use the notebook's core and optional labels to choose your workload. This activity fits within guided class time.
Notes stay in this browser. Download a copy to keep them.
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.