Input & Arithmetic Operations
Programs become useful when they can receive data, process it and produce a result.
Python's input() function reads keyboard input, while arithmetic
operators such as +, //, % and
** allow programs to solve numerical problems.
Learning Objectives
- 11.1.1.5 Organize keyboard inputs
- 11.1.1.6 Use arithmetic operations when solving problems
Craig'n'Dave — Cambridge IGCSE Programming
Choose the part of this lesson you want to reinforce.
Conceptual Anchor
The Smart Calculator Analogy
A program is like a smart calculator.
input() is the keyboard,
arithmetic operators are the calculation buttons,
and print() is the display.
The important difference is that Python must also know whether
the user's input should remain text or be converted to a number.
15
User enters data.
input()
Python receives text.
int("15")
Text becomes a number.
15 * 2
Arithmetic operation.
30
Result is displayed.
Anatomy of input()
age = int(input("Enter age: "))"Enter age: "
Text shown to the user.
input(...)
Receives keyboard input as str.
int(...)
Converts valid integer-form text to int.
age =
The integer value is assigned to the variable.
# input() always returns a string
name = input("Enter your name: ")
age_text = input("Enter your age: ")
# Convert input when numeric operations are needed
age = int(input("Enter your age: "))
price = float(input("Enter the price: "))
# Multiple inputs
x = int(input("x = "))
y = int(input("y = "))Input Simulator
Enter the characters a user might type. The simulator shows what
input(), int() and float() would do.
input()
→
int(input())
→
float(input())
→
Arithmetic Operators
+Addition7 + 3 → 10
-Subtraction7 - 3 →
4*Multiplication7 * 3 →
21/Division7 / 3 →
2.333...//Floor division7 // 3 →
2%Modulo7 % 3 → 1
**Power2 ** 3 → 8
| Operator | Name | Example | Result |
|---|---|---|---|
+ |
Addition | 7 + 3 |
10 |
- |
Subtraction | 7 - 3 |
4 |
* |
Multiplication | 7 * 3 |
21 |
/ |
Division (float result) | 7 / 3 |
2.333... |
// |
Floor division | 7 // 3 |
2 |
% |
Modulo / remainder | 7 % 3 |
1 |
** |
Exponentiation | 2 ** 3 |
8 |
Arithmetic Playground
Try this
Change A and B.
Compare how /, // and %
respond to the same pair of values.
A + BA - BA * BA / BA // BA % BA ** BThe Division Family: / vs // vs %
17 / 5 = 3.4
The quotient as a floating-point result.
17 // 5 = 3
The mathematical floor of the quotient.
17 % 5 = 2
The remainder associated with floor division.
Relationship
For positive integers:
dividend = divisor × (dividend // divisor) + (dividend % divisor).
Example: 17 = 5 × 3 + 2.
Operator Toolbox
n % 2
Even / odd remainder
0 means divisible by 2; 1 is the usual remainder for positive odd integers.
n % 10
Last digit
For a positive base-10 integer, gives the units digit.
n // 10
Remove last digit
Useful when processing positive decimal integers digit by digit.
minutes // 60
Whole hours
Calculates how many complete hours fit in a number of minutes.
minutes % 60
Remaining minutes
Calculates what remains after removing complete hours.
1 Remainder First — No Branching Needed Yet
number = int(input("Number: "))
remainder = number % 2
print("Remainder:", remainder)
# For positive integers:
# remainder 0 → even
# remainder 1 → oddPreview of the Next Lesson
Once you learn Boolean expressions and branching, the same idea can become:
if number % 2 == 0:
print("Even")
else:
print("Odd")Operator Precedence
| Priority | Operators | Description |
|---|---|---|
| 1 — highest | () |
Parentheses |
| 2 | ** |
Exponentiation |
| 3 | * / // % |
Multiplication and division family |
| 4 — lowest here | + - |
Addition and subtraction |
()
Parentheses — evaluate grouped expressions first
**
Exponentiation
* / // %
Multiplication / division level
+ -
Addition / subtraction
Expression Stepper
Follow one operation at a time. The stepper highlights the order Python uses.
Extension: Two exponentiation surprises
# Exponentiation chains are evaluated from the right
2 ** 3 ** 2
= 2 ** (3 ** 2)
= 2 ** 9
= 512
# Unary minus and exponentiation
-2 ** 2
= -(2 ** 2)
= -4
(-2) ** 2
= 4Negative Floor Division
-7 / 2 = -3.5
Exact division.
floor(-3.5) = -4
Floor means the next integer downward.
-7 // 2 = -4
Python floor division result.
Compare with int()
int(-3.5) gives -3 because int()
truncates toward zero. But -7 // 2 gives -4
because floor division moves down toward negative infinity.
Worked Examples
Solve the Problem
Arithmetic Error Lab
Pitfalls & Common Errors
Division by Zero
x / 0, x // 0 and x % 0
raise ZeroDivisionError.
Forgetting to Convert input()
input() returns a string. Therefore
input("Number: ") + 5 attempts to combine str
and int and raises TypeError.
Invalid Numeric Input
If int(input(...)) receives text such as
"hello", conversion raises ValueError.
/ Returns a Float
In Python 3, 10 / 2 gives 5.0,
not integer 5.
// Means Floor Division
It is not simply “remove the decimal part”.
This distinction matters for negative values:
-7 // 2 == -4.
% Means Remainder, Not Percentage
17 % 5 means the remainder after division, which is 2.
** Is Power — Not ^
Use 2 ** 3 for exponentiation.
In Python, ^ has a different meaning (bitwise XOR).
Pro-Tips for Exams
Must-Know
input()returns a string.- Use
int()orfloat()when arithmetic is required. //and%often appear in digit and time-conversion problems.- For positive integers,
n % 2helps determine even/odd. n % 10gives the last decimal digit of a positive integer.n // 10removes the last decimal digit of a positive integer.- Use
**for exponentiation, not^. - Apply operator precedence carefully when tracing expressions.
Graded Tasks
List all seven arithmetic operators in this lesson and state the purpose of each.
Explain the difference between /, //
and % using 17 and 5.
Write a program that reads the radius of a circle and outputs its area.
Use 3.14159 for π.
Convert a total number of seconds into hours, minutes and remaining seconds
using // and %.
For a positive three-digit integer, write expressions that obtain its hundreds, tens and units digits.
Without running Python, evaluate
2 + 3 * 4 ** 2 - 10 // 3.
Show each step in the correct order.
Create a program that asks for three test scores, calculates their average and displays the result rounded to one decimal place.
Exam Practice
Q1: Write the exact output. [2]
x = 17
y = 5
print(x // y, x % y)
Reveal marking points
Q2: State the output and show the order of evaluation. [3]
print(2 + 3 * 4 ** 2)
Reveal marking points
Q3: Write two Python expressions that convert
367 seconds into whole minutes and remaining seconds. [2]
Reveal marking points
Q4: The user enters 12.5. Explain why
int(input("Number: ")) fails and write a suitable alternative. [2]
Reveal marking points
Q5: State the result of -7 // 2 and explain why. [2]
Reveal marking points
Self-Check Quiz
input() return?
str.
17 / 5?
3.4.
17 // 5?
3.
17 % 5?
2.
2 + 3 * 4?
14 — multiplication happens before addition.
-7 // 2?
-4.
^ or **?
**. The ^ operator has a different meaning in Python.