This page will serve as a go to page for lesson, activites and code
Get in TouchThis lesson teaches you thinking using a programming lanuguage.
Programming often entails deciding on what programming structure to use depending on the problem you want to solve.
Use when: You need to store a value (like a number, text, or object) that you’ll reuse or change later.
age = 18
name = "Alex"
Here, you’re storing data that can be referenced or modified later.
Use when: you know (or can determine) how many times you want to repeat an action — for example, looping through a list or range of numbers.
for i in range(5): # repeats 5 times
print("Hello", i)
Use for loops to iterate over sequences (lists, strings, ranges, etc.).
Use when: you want to repeat something until a condition is no longer true — but you don’t know exactly how many times.
count = 0
while count < 5:
print("Counting:", count)
count += 1
Use while loops for repeating actions with a condition that may change during the loop.
Use when: you need to run a block of code only if a condition is true.
age = 18
if age >= 18:
print("You can vote.")
Use if to make a decision in your code.
Use when: you have multiple possible conditions, and only one of them should run.
grade = 85
if grade >= 90:
print("A")
elif grade >= 80:
print("B")
elif grade >= 70:
print("C")
Use if–elif to check several conditions in sequence.
Use when: you want to do one thing if a condition is true, and something else if it’s false.
is_raining = True
if is_raining:
print("Take an umbrella.")
else:
print("Enjoy the sun!")
Use if–else to handle two possible outcomes.
Use when: you have a block of code that you’ll use more than once, or want to organize into a reusable, logical unit.
def greet(name):
print("Hello,", name)
greet("Sam")
greet("Lila")
Use functions to avoid repeating code and make it more organized.
Use when: you need to store multiple items in order, and you might want to change, add, or remove them later.
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
Use lists for ordered, changeable collections of data.
Use when: you want to store key–value pairs, like a name and phone number, or a word and its definition.
student = {
"name": "Alex",
"age": 15,
"grade": "10th"
}
print(student["name"])
Use dictionaries for labeled data where each key points to a specific value.
A list in Python is like a digital backpack where you can store multiple items. Instead of carrying one thing at a time, a list lets you hold many things at once!
For example, imagine you want to store the names of your favorite games:
games = ["Minecraft", "Fortnite", "Roblox", "Among Us"]
Here, games is a list that holds four game names.
Lists are created using square brackets [ ], and items inside the list are separated by commas.
fruits = ["Apple", "Banana", "Cherry"] numbers = [1, 2, 3, 4, 5] mixed = ["Hello", 42, True] # A list can have different types of data!
You can pick items from the list using their position (index). Remember, Python starts counting from 0!
friends = ["Jake", "Emma", "Liam", "Sophia"] print(friends[0]) # Prints "Jake" print(friends[2]) # Prints "Liam"
You can update a list item like this:
fruits = ["Apple", "Banana", "Cherry"] fruits[1] = "Orange" # Changing "Banana" to "Orange" print(fruits) # Output: ['Apple', 'Orange', 'Cherry']
movies = ["Avatar", "Titanic"]
movies.append("Inception")
print(movies) # Output: ['Avatar', 'Titanic', 'Inception']
movies.insert(1, "Avengers") print(movies) # Output: ['Avatar', 'Avengers', 'Titanic', 'Inception']
colors = ["Red", "Blue", "Green"]
colors.remove("Blue")
print(colors) # Output: ['Red', 'Green']
colors.pop(1) # Removes "Blue" (index 1) print(colors)
If you want to go through all items in a list, use a for loop:
for game in games:
print(game)
if "Minecraft" in games:
print("You love Minecraft!")
numbers = [5, 2, 9, 1, 3] numbers.sort() # Sorts from smallest to largest print(numbers) # Output: [1, 2, 3, 5, 9]
myList = []
myList.append("apples")
myList.append(2)
myList.append(3.5)