Unit 11.1A · Term 1

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.

17 // 5 = 3
7
8
9
/
4
5
6
//
1
2
3
%
0
+
*
**
Input 15 User enters data.
Read input() Python receives text.
Convert int("15") Text becomes a number.
Process 15 * 2 Arithmetic operation.
Output 30 Result is displayed.

Anatomy of input()

age = int(input("Enter age: "))
1. Prompt "Enter age: "

Text shown to the user.

2. Read input(...)

Receives keyboard input as str.

3. Convert int(...)

Converts valid integer-form text to int.

4. Store 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 + B
A - B
A * B
A / B
A // B
A % B
A ** B

The Division Family: / vs // vs %

/ Real division 17 / 5 = 3.4 The quotient as a floating-point result.
// Floor division 17 // 5 = 3 The mathematical floor of the quotient.
% Modulo 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 → odd

Preview 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.

Start

                            
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 = 4

Negative 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

Choose an example:


                                

                            

Solve the Problem


                            
Write the Python expressions before revealing.

Arithmetic Error Lab


                            
Decide whether the code is valid or which error occurs.

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() or float() when arithmetic is required.
  • // and % often appear in digit and time-conversion problems.
  • For positive integers, n % 2 helps determine even/odd.
  • n % 10 gives the last decimal digit of a positive integer.
  • n // 10 removes the last decimal digit of a positive integer.
  • Use ** for exponentiation, not ^.
  • Apply operator precedence carefully when tracing expressions.

Graded Tasks

Remember

List all seven arithmetic operators in this lesson and state the purpose of each.

Understand

Explain the difference between /, // and % using 17 and 5.

Apply

Write a program that reads the radius of a circle and outputs its area. Use 3.14159 for π.

Apply

Convert a total number of seconds into hours, minutes and remaining seconds using // and %.

Apply

For a positive three-digit integer, write expressions that obtain its hundreds, tens and units digits.

Analyze

Without running Python, evaluate 2 + 3 * 4 ** 2 - 10 // 3. Show each step in the correct order.

Create

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
3 2

Q2: State the output and show the order of evaluation. [3]
print(2 + 3 * 4 ** 2)

Reveal marking points
4 ** 2 = 16 3 * 16 = 48 2 + 48 = 50 Output: 50

Q3: Write two Python expressions that convert 367 seconds into whole minutes and remaining seconds. [2]

Reveal marking points
minutes = 367 // 60 seconds = 367 % 60

Q4: The user enters 12.5. Explain why int(input("Number: ")) fails and write a suitable alternative. [2]

Reveal marking points
The text "12.5" is not a valid integer-form string, so int() raises ValueError. A suitable alternative is: number = float(input("Number: "))

Q5: State the result of -7 // 2 and explain why. [2]

Reveal marking points
-4 Floor division uses the mathematical floor, so -3.5 is rounded down to -4.

Self-Check Quiz

Seven quick checks Click each answer to reveal
1. What type does input() return?
str.
2. What is 17 / 5?
3.4.
3. What is 17 // 5?
3.
4. What is 17 % 5?
2.
5. What is the result of 2 + 3 * 4?
14 — multiplication happens before addition.
6. What is -7 // 2?
-4.
7. Which Python operator should be used for powers: ^ or **?
**. The ^ operator has a different meaning in Python.