Skip to main content
SingaporeComputer Science

O-Level Computing (7155) Programming in Python: variables and data types, selection, loops and iteration, lists and strings, and functions and procedures

A module overview for O-Level Computing (SEAB 7155) Programming in Python: variables and core data types (int, float, str, bool) and conversion, selection with if/elif/else, for and while loops with accumulators, lists and strings with indexing and slicing, and functions with parameters and return values, for the lab-based Paper 2.

Generated by Claude Opus 4.86 min readSEAB-7155

Reviewed by: AI editorial process; not yet individually human-reviewed

Jump to a section
  1. Why this module matters
  2. Variables and data types
  3. Selection: if, elif and else
  4. Loops and iteration
  5. Lists and strings
  6. Functions and procedures
  7. How this module is examined
  8. Check your knowledge

Why this module matters

Programming in Python is where the syllabus turns ideas into working code. Python is the language of the lab-based Paper 2, taken on a computer with Python and JupyterLab, where you build and test a program against a task. This module covers the Python you need: variables and data types, selection, loops, lists and strings, and functions. Fluency is the difference between finishing the paper and running out of time, so the best preparation is to code little and often, running and checking each program.

This guide ties together the matching dot-point pages, each with its own worked detail and practice. The strands below build into a complete program.

Variables and data types

Start with how values are stored. See Python variables and data types for the core types and conversion.

A variable is a named store for a value. The core types are int (whole numbers), float (decimals), str (text) and bool (True or False). Because input() always returns a string, you must convert with int() or float() before doing arithmetic, and use str() to join a number into a message.

name = input("Name: ")          # str
age = int(input("Age: "))       # converted to int for arithmetic
next_year = age + 1
print(name + " will be " + str(next_year))

Selection: if, elif and else

Next, making decisions. See Python selection and conditions for the syntax and how to order branches.

Selection chooses which code runs based on a condition. Conditions use comparison operators (==, !=, <, >, <=, >=) and logical operators (and, or, not). Order the branches so the most specific condition comes first, because Python takes the first branch whose condition is True.

mark = int(input("Mark: "))
if mark >= 75:
    print("Distinction")
elif mark >= 50:
    print("Pass")
else:
    print("Fail")

Loops and iteration

Repetition is how programs handle many items. See Python loops and iteration for for and while, accumulators, and avoiding infinite loops.

A for loop repeats a known number of times, often with range. A while loop repeats while a condition is True and suits an unknown number of repetitions, but you must ensure the condition eventually becomes False or the loop runs forever. An accumulator is a variable that builds up a running total.

Lists and strings

Programs often hold many values. See Python lists and strings for indexing, length, looping, append and slicing.

A list stores several values in order; a string is a sequence of characters. Both use indexing from 0 (so the first item is index 0) and slicing with a start (included) and stop (excluded). len() gives the length, a for loop visits each item, and append() adds to a list.

scores = [70, 85, 60]
scores.append(90)          # [70, 85, 60, 90]
print(len(scores))         # 4
print(scores[0])           # 70 (first item)
word = "CODE"
print(word[0:2])           # CO (indexes 0 and 1)

Functions and procedures

Finally, breaking a program into reusable parts. See Python functions and procedures for defining and calling them.

A function is a named block of code that does a task, optionally taking parameters (inputs) and giving back a return value (output). Functions avoid repetition, make code readable, and break a problem into smaller testable parts. A function that returns no value is sometimes called a procedure.

def area_of_rectangle(width, height):
    return width * height

print(area_of_rectangle(4, 5))   # 20

How this module is examined

  • Paper 2 (lab-based, 40%). Write and test working Python on a computer with Python and JupyterLab: read input, choose the right type, use selection and loops, handle lists and strings, and use functions to structure the solution.
  • Paper 1 (written, 60%). Read and complete Python or pseudocode on paper, trace its output, and identify or fix errors.

Check your knowledge

Try these, then take the matching quiz for this module.

  1. State why int() is often needed around input() when reading a number. (2 marks)
  2. Name the four core Python data types. (2 marks)
  3. State one situation where a while loop is more suitable than a for loop. (1 mark)
  4. State the index of the first item in a Python list. (1 mark)

Sources & how we know this

  • computer-science
  • sg-o-level
  • seab-7155
  • o-level-computing
  • python
  • programming
  • variables
  • loops
  • functions
  • lists
  • 2026