Course Content
Module 2 – Introduction to Python Programming
In this Introduction to Python module, learners explore Python’s clear, readable syntax and powerful features. Beginning with installation and a simple “Hello, World!” script, you will progress through variables, control flow and functions using step-by-step examples. By the end, you will be equipped to write your own Python programmes, automate routine tasks and tap into an extensive library ecosystem for real-world projects.
0/7
Module 3 – Variables, Data Types and Basic Operations
In the Variables, Data Types and Basic Operations in Python module, learners explore how to store and manage data using variables, master fundamental types such as integers, floats, strings and booleans, and perform arithmetic, comparison and logical operations step by step. Clear explanations, real world examples and hands on exercises guide you through writing and debugging code. By the end of this module, you will be ready to build dynamic Python programs and automate everyday tasks.
0/6
Module 4 – Control Flow – Conditions and Loops
Control flow structures determine the order in which your program’s code executes. With conditional statements, you can make decisions and execute certain code blocks only when specific conditions are met. Loops allow you to repeat actions efficiently without writing redundant code. In this module, we will explore fundamental control flow concepts in Python in a step-by-step manner, similar to Microsoft’s learning curriculum. By the end, you’ll understand how to use if, elif, and else statements (including nested conditions) for decision-making, how truthy and falsy values work in Boolean logic, how to construct for loops (using range() and iterating over collections), how to use while loops along with loop control statements (break and continue), and how to leverage list comprehensions and generator expressions for concise looping. Finally, we’ll apply these concepts in a practical exercise to build an interactive decision-making system. Each section below includes explanations, code examples, and mini-exercises to reinforce the concepts, all formatted for clarity and easy follow-along.
0/8
Module 5 – Functions and Code Organisation
Imagine you need to clean up a messy data set or send a personalised email to each customer. Instead of writing the same steps over and over, you can create a function and call it whenever you need. In this lesson on Functions and Code Organisation, you will learn how to define functions, pass and return information, document your work and group related code into modules for easy reuse and maintenance.
0/3
Introduction to Python Programming (Copy 2)

Control Structures – Conditional Statements in Python

Conditional statements let a program run different pieces of code depending on whether certain conditions are true.
In Python, the main keywords for decision-making are:

  • if – runs code if a condition is true.

  • elif – short for else if, lets you check more conditions if the first was false.

  • else – runs code if none of the above conditions are true.

If Statements

An if statement runs a block of code only when a condition evaluates to True.
The condition is a Boolean expression—something that’s either True or False.

Python uses a colon (:) and indentation to mark the code that belongs to the if.
For example:

# Example: using an if statement
x = 10
if x > 0:
    print("x is a positive number")

print("This always prints, since it's outside the if")
  • The line under if runs only if x > 0 is true.

  • The last print runs no matter what, because it’s not indented under the if.

  • Indentation is very important in Python—by convention, use 4 spaces.

If–Else Statements

Sometimes you want one block if the condition is true, and a different block if it’s false.

# Example: if-else for two branches
temperature = 5
if temperature < 0:
    print("It's freezing cold!")
else:
    print("Temperature is above freezing.")

Here:

  • If temperature < 0 is true → print freezing message.

  • Otherwise → run the else block.
    Only one branch runs.

Using Elif for Multiple Conditions

For more than two possibilities, use elif for extra checks.
Python tests each condition in order until one is true, then skips the rest.

# Example: if, elif, else chain
score = 85

if score >= 90:
    grade = "A"
elif score >= 75:
    grade = "B"
elif score >= 65:
    grade = "C"
else:
    grade = "D"

print("Grade:", grade)
  • If the score is 90+ → Grade A (others skipped).

  • Else if 75+ → Grade B.

  • Else if 65+ → Grade C.

  • Otherwise → Grade D.

Only the first matching condition runs.

Nested If Statements

You can put an if inside another if to handle more complex logic.

# Example: nested if statements
num = 7
if num >= 0:
    print("Number is non-negative")
    if num == 0:
        print("Number is zero")
    else:
        print("Number is positive")
else:
    print("Number is negative")

Explanation:

  • Outer if checks if num >= 0.

  • If true, it runs another if to check if the number is exactly 0.

  • Else inside it handles positive numbers.

  • Outer else handles negative numbers.

Too much nesting can be hard to read—often you can replace it with elif or logical operators.

Key Points

  • All if-conditions are evaluated as True/False (truthy/falsy).

  • Indentation defines scope—wrong indentation will cause errors.

  • You can have one else and many elif clauses.

  • If no condition matches and there’s no else, nothing happens.

  • Python has no switch-case; use elif or dictionaries instead.

  • Use pass as a placeholder for an empty if block.

Mini-Exercise

Write code to determine ticket fees based on age:

age = int(input("Enter your age: "))
# If age under 5 → "Free entry"
# If age 5 to 12 → "Child ticket"
# If age 13 to 59 → "Adult ticket"
# Otherwise (60+) → "Senior discount"

Task:

  • Fill in the if-elif-else statements to handle these 4 cases.

  • Test with different ages to make sure each branch works.