This course is designed especially for kids, not for professional programmers. It uses small, playful examples to build strong coding logic one step at a time. Read a topic, predict what the example will do, then practise changing it.
Python is a language for giving a computer clear instructions. Think of the computer as a very helpful robot: it can do amazing things, but it needs each step written precisely. The coding practice page is your safe place to type and run these instructions - no installation needed.
print('Hello, Python!')
print('I can give a computer instructions.')
Kid coder habit: Before pressing Run, say out loud what you think the computer will show. Predicting first is a powerful way to grow your logical thinking.
1. Output, values and variables
print() displays a value. A value can be text (a string), a number, or the result of a calculation. A variable gives a value a meaningful name so it can be used again.
name = 'Maya'
apples = 4
apples = apples + 2
print(name, 'has', apples, 'apples')
Read it step by step:= stores a value; it does not ask whether two things are equal. The third line replaces the old value of apples with 6.
Common mix-up: Text needs quotation marks, but a variable name does not: use print(name), not print('name').
Python maths
Python can be your calculator. Use + to add, - to subtract, * to multiply, / to divide, ** for powers, and % to find the leftover after division.
Logic challenge: A number is even when number % 2 is 0. Change 7 to 8 and predict the leftover before running the code.
2. Decisions with if
Programs can make choices by testing a condition. A condition is either True or False. Use == to compare, and use indentation to show which lines belong to a choice.
Useful comparisons:== equal to, != not equal to, > greater than, and >= greater than or equal to.
3. Repetition with loops
A for loop repeats for every item in a collection or every number from range(). A while loop repeats while a condition remains true.
for number in range(1, 4):
print(number)
count = 0
while count < 3:
print('Go!')
count = count + 1
Watch out:range(1, 4) gives 1, 2, 3—not 4. A while loop must change something that eventually makes its condition false.
4. Functions
A function names a reusable set of instructions. Parameters are the inputs it receives. return sends a result back so another part of the program can use it.
def double(number):
return number * 2
answer = double(6)
print(answer)
When to use one: If you would copy the same steps more than once, put those steps in a function and call it with different values.
5. Strings
A string is text. You can join strings, inspect their length, and make changed versions with methods. Methods use a dot because they belong to that string.
Remember: Most string methods return a new string. message.upper() does not change message unless you store the result.
Asking questions with input()
input() lets a program ask a person for an answer. The answer arrives as text, even when someone types a number. Use int() when you need a whole number for maths.
name = input('What is your name? ')
age = int(input('How old are you? '))
print(f'Hi {name}! Next year you will be {age + 1}.')
Important:input() answers are strings. Without int(), trying to add 1 to an age can cause a TypeError.
6. Lists and dictionaries
Use a list for an ordered set of values. Its first position is index 0. Use a dictionary when each value needs a label, called a key.
Choose carefully: Lists answer “what is at position 0?” Dictionaries answer “what is this student's score?”
7. Classes and objects
A class is a blueprint. An object is one thing created from that blueprint. __init__ sets up each new object, and self refers to that individual object.
class Dog:
def __init__(self, name):
self.name = name
def introduce(self):
print('I am', self.name)
pet = Dog('Bruno')
pet.introduce()
Why use classes? They keep related data and actions together when a program represents several similar things.
Fixing mistakes: debugging
Errors are clues, not failures. Read the last line of an error message first: it usually names the problem and the line to check. Common beginner errors are a missing quote or colon (SyntaxError), a misspelled name (NameError), uneven spaces (IndentationError), and mixing text with numbers (TypeError).
# Fix the missing colon before running:
score = 10
if score >= 5:
print('Great work!')
Debugging routine: Read the message, find the line, change one small thing, and run again.
Mini projects: combine your skills
A project is where separate ideas become a real program. Start small, make it work, then add one improvement at a time. Try a Mad Libs story, calculator, number guessing game, rock-paper-scissors, or a to-do list.
tasks = ['Read a chapter', 'Practise Python']
for task in tasks:
print('- ' + task)
tasks.append('Build a mini project')
print('Total tasks:', len(tasks))
Build challenge: Turn this into your own to-do list. Add a task, remove a task, and print every task with a loop.
8. Algorithms and problem solving
An algorithm is a clear series of steps that solves a problem. Test it with ordinary, boundary, and empty cases. A list comprehension is a compact loop for building a list.
numbers = [1, 2, 3, 4]
squares = [number ** 2 for number in numbers]
print(squares)
target = 3
print(target in numbers)
Think before coding: State the input, expected output, and steps in plain language first. Then test your code with examples that could reveal a mistake.
Check your understanding: quick Q&A
Open each question, think of your answer, then check it. Use the quiz afterwards for a scored challenge.
Q: What is the difference between = and ==?
A:= stores a value in a variable. == compares two values to see whether they are the same.
Q: Why does range(1, 4) stop at 3?
A: The end of a Python range is not included, so it makes 1, 2, and 3.
Q: Why might age + 1 give an error after input()?
A:input() gives text. Use int(age) to turn a whole-number answer into a number first.
Q: What should I do when my code shows an error?
A: Read the final line of the message, check the line it names, make one small change, and run again.