Chapter 013 / 132 · Level 1 · Beginner Python textbook

Numbers and useful calculations

Complete Python PDF
Checking PDF availability…

Chapter 13 of 132 · Level 1 · Beginner Python textbook · 6 real coding demonstrations + 2 worked code answers. Learn through reading, predicting and testing real Python code.

Code + real outputPractice + explanationsOffline Python exercises
Course disclaimer · independent educational content
EasyTutorGuide creates independent educational tutorials. Python and other product names remain the property of their owners; this course is not endorsed by the Python Software Foundation or third-party providers. Examples are for learning and should be reviewed and tested before production use. Do not expose real API keys or private data. Translation is automated and may introduce errors; code examples remain untranslated. Terms · Privacy · Legal.
01 · Start here: simple explanation

Calculations are not just school exercises: they help with prices, savings, time, measurements, and program decisions.

Python uses + to add, - to subtract, * to multiply, / to divide, // for floor division, % for remainder, and ** for powers. Parentheses make the calculation order explicit.

The expression 7 / 2 produces 3.5, whereas 7 // 2 produces 3. The remainder 7 % 2 produces 1. These differences matter when grouping items into boxes or checking whether a number is even.

Floats are convenient approximations, not exact representations of every decimal fraction. For introductory display, formatting to two decimal places is useful. For real financial systems, use Decimal or integer cents as appropriate.

Whenever you calculate, give the result a meaningful name. Instead of a long expression hidden inside print, separate subtotal, tax, and total to make each step inspectable.

02 · Learning objectives and technical words

By the end you can…

  • Use arithmetic operators correctly
  • Understand division, integer division, and remainder
  • Avoid confusing rounding with exact money arithmetic

Words you should know

expression
code that evaluates to a value
operator
a symbol that performs an operation
remainder
what is left after division into whole groups
float
a numeric type with limited decimal precision
03 · Point-by-point: understand the idea
PINPOINT LEARNING

Locate the input, identify the Python instruction that changes it, and compare the printed result. Make a prediction before each run so you understand what the program does—not only how to copy it.

The mathematical result 0.1 + 0.2 is not stored as exactly 0.3 in a binary float. Avoid using == between arbitrary computed floats when exact equality matters.

04 · Coding examples with real outputs

Example 1: Arithmetic toolbox

Python · runnable
PYTHON CODE
print(8 + 3)
print(8 - 3)
print(8 * 3)
print(8 / 2)
Verified execution ▼
11
5
24
4.0

Why it works: Read each operator aloud while checking the result.

Example 2: Division, groups, and leftovers

Python · runnable
PYTHON CODE
print(7 / 2)
print(7 // 2)
print(7 % 2)
Verified execution ▼
3.5
3
1

Why it works: / gives a float, // gives the number of whole groups rounded down, and % gives leftovers.

Example 3: Calculate an order total

Python · runnable
PYTHON CODE
price = 19.99
quantity = 2
subtotal = price * quantity
print(f"Subtotal: ${subtotal:.2f}")
Verified execution ▼
Subtotal: $39.98

Why it works: :.2f displays a number using two digits after the decimal point.

Example 4: Calculate sales tax

Python · runnable
PYTHON CODE
subtotal = 40
tax_rate = 0.13
tax = subtotal * tax_rate
total = subtotal + tax
print(f"Tax: ${tax:.2f}")
print(f"Total: ${total:.2f}")
Verified execution ▼
Tax: $5.20
Total: $45.20

Why it works: Separate the tax and total calculations; this makes errors easier to spot.

Example 5: Work out minutes and seconds

Python · runnable
PYTHON CODE
total_seconds = 145
minutes = total_seconds // 60
seconds = total_seconds % 60
print(minutes, "min", seconds, "sec")
Verified execution ▼
2 min 25 sec

Why it works: Use floor division for whole minutes and remainder for extra seconds.

Example 6: Order of operations

Python · runnable
PYTHON CODE
print(2 + 3 * 4)
print((2 + 3) * 4)
Verified execution ▼
14
20

Why it works: Multiplication runs before addition unless parentheses change the order.

05 · Exercises, debugging and worked answers

Try without looking

  1. Find the price for 4 pens costing $1.25 each.
  2. Calculate how many full boxes of 6 fit into 29 apples.
  3. Find the leftover apples after filling those boxes.

Worked answers

Worked solution 1: Worked answer: pens

Python · runnable
PYTHON CODE
unit_price = 1.25
count = 4
print(f"${unit_price * count:.2f}")
Verified execution ▼
$5.00

Why it works: The multiplication gives the order price.

Worked solution 2: Worked answer: boxes

Python · runnable
PYTHON CODE
apples = 29
print("Full boxes:", apples // 6)
print("Leftover:", apples % 6)
Verified execution ▼
Full boxes: 4
Leftover: 5

Why it works: Use // for complete boxes and % for the remainder.

06 · Build a mini-project and review

Mini-build: A receipt that calculates subtotal, 13% sample tax, and total for three products.

Progress check

Can you explain the output before running the code? Can you change the inputs without breaking the program? Revisit the examples until you can do both.