WeLearn

Grade 12 Information Technology · Lesson 6.1

Program Flow Controls and Syntax in Python

Unit 6: Fundamentals of Programming

Python is a popular, beginner-friendly programming language with clear syntax. Syntax means the rules for writing valid code. Python uses indentation (normally four spaces) to group statements into blocks instead of braces; a colon (:) ends the line that starts a block. Python is case-sensitive (Total and total are different names), and variables are created by assignment, e.g. price = 25.

Key terms

Syntax
rules for writing valid code
Indentation
spaces that group statements into a block
Sequence
statements executed in order
Selection
choosing a path with if/elif/else
Iteration
repeating code with loops
for loop
repeats over a sequence or range
while loop
repeats while a condition is True
Infinite loop
a loop whose condition never becomes False
All Grade 12 Information Technology key terms →

Summary

  • Python uses indentation and colons to form blocks.
  • Flow control: sequence, selection (if/elif/else), iteration (for, while).
  • == compares; = assigns.
  • Convert input() text with int() or float().

In everyday life: Mobile money apps such as telebirr use selection (if the balance is enough, allow the transfer) and loops (process each transaction) written in programming languages.

Check yourself

  • What does range(2, 10, 2) produce?
  • Write an if/elif/else that grades a mark as A (≥85), B (≥70) or C.
  • How can a while loop become infinite?

Practice questions

  1. 1. In Python, which operator checks whether two values are equal?

    • A. =
    • B. ==
    • C. !=
    • D. :=
    Show answer

    Answer: ==

    == compares values and gives True or False; a single = assigns a value to a variable.

  2. 2. How many times does the body of the loop for i in range(3, 10): run?

    Show answer

    Answer: 7

    range(3, 10) produces 3, 4, 5, 6, 7, 8, 9 - it stops before 10 - which is 7 values.

On WeLearn

The full lesson: reading notes, worked examples, class activities and the Unit 6 quiz

Study Program Flow Controls and Syntax in Python on WeLearn

Teach Program Flow Controls and Syntax in Python with WeLearn

We will bring a demo to your school: a lesson on your interactive TV, a virtual lab and a classroom game, with your own teachers.