Programming

Programming Fundamentals with Python

Learn how variables, decisions, loops, and functions work together in a small Python program.

Explanation

Programming turns a solution into instructions a computer can execute. This lesson introduces variables for storing values, conditional statements for making decisions, loops for repetition, and functions for organizing reusable behavior.

Students build a grade-summary program and test it with normal, boundary, and invalid inputs. The activity emphasizes tracing program state before relying on trial and error.

Learning activities

  1. Trace a short program and record each variable value.
  2. Build a grade-summary program using a function and loop.
  3. Test the program with boundary and invalid inputs.

Code example

python
def average(scores):
    return sum(scores) / len(scores)

scores = [88, 91, 85]
print(f"Average: {average(scores):.2f}")

Knowledge check

1. What is the main purpose of a function?

  • Store files
  • Group reusable behavior
  • Connect to Wi-Fi
Show answer

Group reusable behavior

References