How small pieces combine to build entire programs — step by step.
Expression
Statement
Block
Control Flow
Function
Class
Module
Package
Level 1
Expression
The smallest unit that produces a value. Combine variables and operators to create an expression.
price+*+tax
=price * tax
Arithmetic
a + b * 2
Comparison
age >= 18
Function Call
len("hello")
Check Your Understanding
1. Which of these is an expression?
x = 10
That's an assignment statement, not just an expression.
x + y * 2
Correct! It combines variables and operators to produce a value.
if x > 5:
That's a control flow keyword, not an expression on its own.
2. What does an expression always produce?
A side effect
Side effects come from statements, not expressions alone.
An error
Expressions don't inherently produce errors.
A value
Correct! Every expression evaluates to a value.
Level 2
Statement
A statement is a complete instruction that performs an action. An expression becomes a statement when it does something — assigns, declares, calls, or controls.
expression+action
=statement
Assignment Statement
total = price * tax
Declaration Statement
int count = 0
Function Call Statement
print("Hello World")
Return Statement
return result
Import Statement
import math
Check Your Understanding
1. Which is NOT a type of statement?
x = 5 (assignment)
Assignment is a valid statement type.
print("hi") (call)
Function call is a valid statement type.
a + b (bare expression)
Correct! A bare expression like a + b computes a value but doesn't do anything with it — it's not a useful statement.
2. What turns an expression into a statement?
Adding parentheses
Parentheses only group expressions, they don't create a statement.
Performing an action (assign, declare, call, return)
Correct! A statement does something — it assigns, declares, calls, or controls flow.
Adding a semicolon
Semicolons are syntax, not what defines a statement conceptually.
Level 3
Block
A block is a group of statements that execute together sequentially. Indentation or braces define a block's boundary.
stmt 1+stmt 2+stmt 3
={ block }
Python Block (indentation)
x = 10
y = x * 2
print(y)
Java Block (braces)
{
int x = 10;
int y = x * 2;
System.out.println(y);
}
Check Your Understanding
1. What defines the boundaries of a block?
Indentation (Python) or braces (Java/C)
Correct! Different languages use different syntax to mark block boundaries.
Blank lines between statements
Blank lines don't define blocks — they're just whitespace.
Comments in the code
Comments are ignored by the compiler. They don't define blocks.
2. Can a block contain just one statement?
No, it needs at least two
A block can have any number of statements, including just one.
Yes, even a single statement can form a block
Correct! A block can have one or many statements.
Level 4
Control Flow
Control flow structures decide which blocks run and how many times. They give your code decision-making and repetition.
condition+block
if...elseforwhile
If / Else — decision
if age >= 18:
print("Adult")
else:
print("Minor")
For — iteration
for i in range(5):
print(i)
While — conditional loop
while count < 10:
count += 1
Check Your Understanding
1. What two things does a control flow structure need?
A variable and operator
Those make an expression, not control flow.
A function and a class
Those are higher-level constructs.
A condition and a block
Correct! Control flow = condition (what to check) + block (what to do).
2. What's the difference between for and while?
for is faster than while
Speed is not the difference — it's about when you know the iteration count.
for iterates a known range; while runs until a condition flips
Correct! Use for when you know how many times; while when you don't.
They are identical
They serve different use cases based on whether iteration count is known.
Level 5
Function
A function is a named, reusable block with parameters (inputs) and a return value (output). It doesn't need read/print — many functions do pure computation.
name+params+block+return
=def function()
Pure computation (no I/O)
def area(radius):
return 3.14 * radius ** 2
With control flow inside
def grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
else:
return "C"
Check Your Understanding
1. Does every function need print() or input()?
Yes, that's how functions communicate
Functions communicate through parameters and return values, not I/O.
No, many functions use only params and return
Correct! Functions take input via parameters and give output via return — no print/input needed.
2. What makes a function different from a plain block?
It has a name, parameters, and can be reused
Correct! Name + params + return + reusability = function.
It runs faster
Functions aren't about speed — they're about structure and reusability.
It must contain a loop
Functions don't require loops — they can contain any statements.
Level 6
Class
A class bundles related functions (methods) and data (attributes) into a single blueprint. Objects are created from classes.