Chapter 2

Names, Numbers, and Text

Explain the names, calculations, and text report used by the first program. Name each reading, calculate the mean, format one labelled result, and inspect a value when its behavior is surprising.

The first chapter used names such as total, count, and mean because they made a small calculation readable. We could run and change that program without explaining every symbol. Now we will return to the same report and account for each part of it.

First, each temperature reading receives a name. We then calculate with those numerical values and place the result inside a short line of text. Keeping one report throughout the chapter lets us see why each new idea is needed instead of learning a list of disconnected Python features.

By the end, you will be able to read a familiar line from its inner values to its complete effect. You will also know how to inspect a value whose behavior is surprising and when a conversion from text to a number is justified. The next chapter removes the repeated reading names by letting a program choose and repeat work.

After this chapter

  • Trace assignment and reassignment by reading the right side before updating the name on the left.
  • Calculate the report's total and mean and verify evaluation order with a hand calculation.
  • Build a labelled report that keeps numerical values separate from text and display formatting.
  • Identify literals, names, operators, expressions, function calls, arguments, and complete statements in familiar lines.
  • Inspect an unexpected value and convert it only when its meaning supports the new type.

Lessons

  1. 01
    Names Refer to Values

    Trace assignment and reassignment, then choose valid, readable names for the report's values.

    3 exercises
  2. 02
    Calculate with Numbers

    Calculate with integers and floats, follow evaluation order, and verify groups, remainders, powers, and rounding.

    3 exercises
  3. 03
    Build a Text Report

    Distinguish strings from numbers and build a labelled, fixed-decimal report with an f-string.

    3 exercises
  4. 04
    Read a Line of Python

    Identify the parts of familiar Python lines and read nested expressions from the inside outward.

    3 exercises
  5. 05
    Inspect and Convert Values

    Inspect unexpected values, trace their assignments, and convert numerical text for a clear reason.

    3 exercises

Review and practice

  1. Review

    Review assignment, arithmetic, strings, line reading, type inspection, and purposeful conversion.

  2. Exercises

    Trace, calculate, name, format, repair, and vary the chapter's measurement report.

Chapter progress