Rule
A rule in programming is a guideline that tells you how code should be written and behave. These rules help make sure your program works properly and is easy to understand.
Syntax rules
Using the correct structure (e.g. brackets, semicolons).
Naming rules
Using clear names for variables (e.g. totalMarks, not x).
Control rules
Deciding how the program runs and can include: sequence, selection and iteration.
Sequence
is a control rule and outlines how steps run in order.
Selection
is a control rule about making decisions (if, else).
Iteration
is a control rule about repeating steps (for, while loops).
Validation rules
Checking if data is correct (e.g. age must be between 0–120).
Error handling rules
What to do if something goes wrong.
Strings
A string is a sequence of characters enclosed in quotes. It can include letters, numbers, symbols, and spaces. For example: name = “Bob”
Integers
An integer is a whole number (no decimal point). For example: age = 30
Floats
A float is a number that has a decimal point. For example: price = 19.99
Lists
A list is an ordered collection of items (which can be of any type), enclosed in square brackets. For example: colors = [“red”, “green”, “blue”]
Dictionaries
A dictionary is a collection of key-value pairs, enclosed in curly braces. For example: person = {“name”: “Bob”, “age”: 30, “city”: “Ballarat”}
Control Structures
These are used to control the flow of a program. Common ones include:
if/elif/else: Conditional logic.
For example:
# if statement
if age > 18:
print(“Adult”)
for and while loops: Repeating actions
For example:
# for loop
for color in colors:
print(color)
Modules
A module is a file containing Python code (functions, variables, classes) that you can import and use in your program. For example: import math
Variables
A variable stores data that can be used and changed throughout a program. For example:
message = “Welcome!”
count = 5
Print Statements
The print() function displays output to the console. print(“Hello, Bob!”)
Boolean
A data type that represents one or two values: True or False.
Casting
The process of converting one data type to another. Example: int(input(“Enter a number”)) converts a string to an integer
Function
A pre-made block of code designed to perform a specific task. Examples include print() and input()
Input Function
A function that promotes the use to enter data, which is stored as a string. Example: input(“What is your name?”)
Print Function
a function used to display an output of the screen. Example: print(“Hello World”). Also known as a print statement
Syntax error
An error caused by breaking the rules of the programming language, such as incorrect punctuation or spacing.