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)

For Loops with range() and Iterating Over Collections

A for loop in Python is used to iterate over the elements of a sequence or other iterable (like lists, strings, tuples, dictionaries, sets, etc.), executing a block of code for each element.

Python’s for loop works more like the “for-each” loop in other languages rather than the traditional C-style loop with an index.

This means:

  • No need to manually manage an index or increment a counter.

  • Python handles stepping through the sequence automatically.

Iterating Over a Sequence

Syntax:

for <variable> in <sequence>:
    <block of code>
  • On each iteration:

    • <variable> is assigned the next element from <sequence>.

    • The code block executes using that value.

  • Loop continues until all elements are processed.

Example – looping through a list:

fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print("I have a", fruit)

Output:

I have a apple
I have a banana
I have a cherry

💡 The loop runs 3 times (once for each fruit). No index like i++ is needed.

Example – looping through a string:

for ch in "PYTHON":
    print(ch, end=" ")

Output:

P Y T H O N

Example – looping through a dictionary:

mydict = {"name": "Alice", "age": 25}
for key, val in mydict.items():
    print(key, ":", val)

Output:

name : Alice
age : 25

💡 Tip:
If you need both the index and value, use enumerate():

for idx, val in enumerate(["a", "b", "c"]):
    print(idx, val)

The range() Function for Numeric Loops

range() generates a sequence of numbers, which you can loop over.

Basic example:

for i in range(5):  # 0 to 4
    print("Iteration", i)

Output:

Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 4

Custom start and step:

print(list(range(2, 6)))      # [2, 3, 4, 5]
print(list(range(0, 10, 2)))  # [0, 2, 4, 6, 8]
print(list(range(10, 0, -1))) # [10, 9, 8, ..., 1]

Example – summing numbers:

total = 0
for n in range(1, 6):  # 1 to 5
    total += n
print("Sum of 1 to 5 is", total)

Output:

Sum of 1 to 5 is 15

Example – ignoring the loop variable:

for _ in range(3):
    print("Hello")

Output:

Hello
Hello
Hello

Break and Continue

  • break → Stop the loop immediately.

  • continue → Skip current iteration, go to next.

Example – using break & continue:

numbers = [1, 3, 7, 10, 15]
for num in numbers:
    if num == 10:
        print("Found 10! Stopping the search.")
        break
    if num % 2 == 0:
        continue
    print("Odd number:", num)

Output:

Odd number: 1
Odd number: 3
Odd number: 7
Found 10! Stopping the search.

💡 Key points:

  • break → jumps out of the loop entirely.

  • continue → skips to the next iteration.

  • Works in both for and while loops.

Recap:

  • Use for item in collection when iterating over items.

  • Use for i in range(n) when looping a fixed number of times.

  • Use enumerate() if you need an index.

  • Use break to stop early, continue to skip iterations.

Mini-Exercise:

  1. Loop over the string "LOOP" and print each character on its own line.

  2. Use range(1, 11) to print all even numbers from 1 to 10.

  3. Write a loop that goes through a list and stops if it finds "STOP".