AHS CODING CLUB

Welcome to AHS Code Club Tuesdays

This page will serve as a go to page for lesson, activites and code

Get in Touch
Click Here to Open Python Interpreter Exercises

When to USE

This 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.

Variables

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.

For Loop

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.).

While loop

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.

If Statement

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.

If–Elif Statement

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.

If–Else Statement

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.

Function

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.

List

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.

Dictionary

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.

1 - What is a List?

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.

2 - Creating a List

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!

3 - Accessing the Items in the List

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"

5 - Changing List Items

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']

6 - Adding Items to a List

Use .append() to add an item at the end:

movies = ["Avatar", "Titanic"]
movies.append("Inception")
print(movies)  # Output: ['Avatar', 'Titanic', 'Inception']

Use .insert() to add an item at a specific position:

movies.insert(1, "Avengers")
print(movies)  # Output: ['Avatar', 'Avengers', 'Titanic', 'Inception']

7 - Removing Items from a List

Use .remove() to delete a specific item:

colors = ["Red", "Blue", "Green"]
colors.remove("Blue")
print(colors)  # Output: ['Red', 'Green']

Use .pop() to remove an item by index (or the last item if no index is given):

colors.pop(1)  # Removes "Blue" (index 1)
print(colors)

8 - Looping Through a List

If you want to go through all items in a list, use a for loop:

for game in games:
    print(game)

9 - Checking if an Item is in a List

Use the in keyword:

if "Minecraft" in games:
    print("You love Minecraft!")

10 - Sorting a List

Want to put your list in order? Use .sort().

numbers = [5, 2, 9, 1, 3]
numbers.sort()  # Sorts from smallest to largest
print(numbers)  # Output: [1, 2, 3, 5, 9]

11 - Creating an Empty List and Adding Members to It

myList = []
myList.append("apples")
myList.append(2)
myList.append(3.5)

Exercises to Submit

Try creating a list of your top 5 favorite songs, and then: Print the first and last song. Add a new song to the list. Remove one song from the list. Print the final list.

Submit Code Here