Adrian Dane

Python 30‑by‑30 Course

Module 1: Foundations and the Python Mindset

Welcome to your first week! We'll start by setting up your coding workshop and learning the absolute basics. Each day is a short, focused session. Just give it 30 minutes, and you'll be amazed at what you can do.

Contents

Day 1: Getting Started and Your First Chat with Python

Objectives

Every new journey has a first step. Today, we're setting up your coding environment. Think of it as preparing your workshop. First, head over to python.org and download the latest stable release for your system (Windows, macOS, or Linux). When you install it, especially on Windows, make sure to check the box that says "Add Python to PATH." This little step saves a lot of headaches later!

Once installed, open your terminal (or Command Prompt) and type python3 --version. If you see a version number, you're all set! Now, type python3 and hit Enter. You'll see a >>> prompt. This is the REPL (Read-Eval-Print Loop), and it's your new best friend. It’s like a direct chat with Python. Try some maths like 2 + 2 or 5 * 10. The REPL is perfect for quick experiments without having to save a file.

While the REPL is great for testing, most of your work will live in scripts. Open any simple text editor (like VS Code, Sublime Text, or even Notepad) and create a file named hello.py. Inside, type this one line: print('Hello, world!'). Save it. Now, in your terminal, navigate to where you saved the file and run it with python3 hello.py. You just ran your first program! Let's make it interactive. Add these lines: name = input('What is your name? ') and then print('Hello, ' + name + '!'). You're now taking input and using a variable (name) to store it. This simple cycle—edit, run, repeat—is the core of all programming.

🤯 Feeling Overwhelmed? Click for a Simpler Explanation!

Don't worry, today is all about three simple ideas:

  • 1. Installing Python: This is just like installing any app, like Spotify or Chrome. You only have to do it once. It gives your computer the ability to understand the Python language.
  • 2. The REPL (>>>): Think of this as a calculator on steroids or a magic 8-ball. You type one command, and it gives you an answer right away. It's a playground for trying things out without any pressure.
  • 3. The Script (.py file): This is like a recipe card. You write down all the instructions in order and save them. Then you tell Python, "run this recipe," and it follows your instructions from top to bottom. That's all a program is!

The variable, like name, is just a labelled box where you can store something, like the name someone types in.

Practice ✍️

Try making a script that asks for the user's favourite food and then replies with "Oh, I love [food] too!". Use an f-string (f"Hello, {name}!") for a cleaner way to print. Can you also ask for their age and tell them what year they'll turn 100?

Click to see a sample script
# hello_age.py
import datetime

name = input("What is your name? ")
age = int(input("How old are you? ")) # input() gives text, int() turns it into a number
current_year = datetime.date.today().year
year_turn_100 = current_year - age + 100
print(f"Hello, {name}! You will turn 100 years old in {year_turn_100}.")
          

Day 2: Talking to Python with Numbers and Words

Objectives

Python is pretty smart; it usually figures out what kind of data you're using without you having to tell it. Today, we'll focus on the two most common types: numbers and text. Python has two main types of numbers: integers (whole numbers like 10, -5, 0) and floats (numbers with a decimal point like 3.14 or -0.5). You can do all the usual maths with them: +, -, * (multiply), / (divide), and even ** for exponents (like 2 ** 3 is 8).

Text in Python is called a string, and you create one by putting quotes around it, like 'Hello' or "Python is fun!". Strings can't be changed in place (they're "immutable"), but you can create new ones from them. You can join them with + ('snow' + 'ball' becomes 'snowball') or repeat them with * ('ha' * 3 becomes 'hahaha'). Strings also have handy built-in tools called methods. For example, 'Hello'.lower() gives you 'hello', and ' some text '.strip() removes the extra spaces.

One of the most important skills is converting between types. The input() function always gives you a string, even if the user types a number. So, if you want to do maths with it, you need to convert it first using int() or float(). For example, age = int(input("Age? ")). To put a number into a sentence, you can convert it back to a string with str(), but it's much easier to use an f-string: f"You are {age} years old.". The f-string automatically handles the conversion for you!

🤯 Feeling Lost in Types? Click for a Simpler Explanation!

Think of data types like different kinds of Lego bricks:

  • Integers (int): These are your solid, whole-number bricks. 5, -12, 1000. Perfect for counting things.
  • Floats (float): These are your measurement bricks, with decimal points. 1.5, 98.6, -0.25. Great for things like temperature or prices.
  • Strings (str): These aren't numbers at all. They're just text. "Alice", "I love pizza", "123" (this is the text '123', not the number!).

You can't do maths with a string! 5 + "Bob" makes no sense. That's why we convert. int("25") turns the text "25" into the number 25 so you can do maths with it. An f-string like f"Score: {score}" is a magic tool that puts your number variable right into a sentence for you.

Practice ✍️

Write a simple tip calculator. Ask for the bill amount and the percentage of tip you want to leave. Calculate and print the tip amount and the total bill. Make sure to format the output to show exactly two decimal places (hint: use an f-string like f"{total:.2f}").

Click to reveal a sample solution
# tip_calculator.py
bill_amount_str = input("What is the total bill? $")
tip_percentage_str = input("What percentage tip would you like to give? ")

# Convert strings to numbers (floats) to do math
bill_amount = float(bill_amount_str)
tip_percentage = float(tip_percentage_str)

tip_amount = bill_amount * (tip_percentage / 100)
total_bill = bill_amount + tip_amount

# Use an f-string with formatting to show two decimal places
print(f"Tip amount: ${tip_amount:.2f}")
print(f"Total bill: ${total_bill:.2f}")
          

Day 3: Making Decisions with "If This, Then That"

Objectives

A lot of programming is about making decisions. Should the player get a bonus? Is the user's password correct? To answer these questions, Python uses a special type called a boolean. It has only two possible values: True or False. You get a boolean whenever you compare things. For example, 5 > 3 is True, and 10 == 20 (notice the double equals == for comparison) is False.

We can also combine these questions using logical operators: and, or, and not. For example, to check if an age is suitable for a teen movie, you might write age >= 13 and age <= 18. This whole expression will only be True if both parts are true. Python is smart about this: if the first part of an and is false, it doesn't even bother checking the second part!

The real power comes when you use these booleans with an if statement. This lets your code take different paths based on a condition. The structure is simple: if a condition is true, do something. You can add an elif (short for "else if") to check another condition, and an else to catch everything that didn't match the previous conditions. Remember, the indentation (the spaces at the start of the line) is how Python knows which code belongs to which block. It's super important!

if condition:
    # This block runs if the condition is True
elif another_condition:
    # This runs if the first was False, but this one is True
else:
    # This runs if nothing above was True
🤯 Confused by Conditions? Let's Simplify!

Think of it like deciding what to wear:

The Question (Comparison): "Is it raining outside?" The answer is either True (yes) or False (no). That's a boolean!

The Logic (if/else):

  • IF it's raining is True...
    ...I will take an umbrella.
  • ELSE (meaning, if it's not raining)...
    ...I will wear sunglasses.

That's all an if/else statement is! It's a way for your program to follow different instructions based on a True or False answer. The elif is just like adding another question in the middle: "Okay, it's not raining, but ELSE IF it's cloudy..."

Practice ✍️

Write a program that asks for a temperature in Celsius. If the temperature is above 30, print "It's a hot day!". If it's between 15 and 30, print "It's a lovely day." Otherwise, print "It's cold, you might need a jacket."

Click to see a sample implementation
# weather_checker.py
temp_celsius = float(input("Enter the temperature in Celsius: "))

if temp_celsius > 30:
    print("It's a hot day! Don't forget sunscreen. ☀️")
elif 15 <= temp_celsius <= 30:
    print("It's a lovely day. Perfect for a walk! 🌳")
else:
    print("It's cold, you might need a jacket. 🧥")
        

Day 4: Storing Things in Lists

Objectives

So far, we've stored one piece of information in a variable at a time. But what if you have a collection of things, like a to-do list or a group of names? For that, we use a list. A list is an ordered, changeable collection of items, written inside square brackets []. For example: tasks = ["buy milk", "walk the dog", "learn Python"].

You can access any item by its position, or index, which starts at 0. So tasks[0] would give you "buy milk". Lists are flexible (or "mutable"). You can add items to the end with .append(), remove them with .remove(), or change an existing item like tasks[1] = "feed the cat". A for loop is the perfect way to go through each item in a list and do something with it: for task in tasks: print(task).

Sometimes you have a collection that you know should never change, like the coordinates of a point (x, y). For this, Python gives us tuples. They are just like lists, but you create them with parentheses () and—this is the key part—they are immutable (unchangeable). Once you create point = (10, 20), you can't change what's inside. This makes your code safer and signals to other programmers (or your future self!) that this data is meant to be constant.

🤯 Lists vs. Tuples? Let's Use an Analogy!

It's all about whether you can edit it or not.

  • A List [] is a Shopping List in Pencil. ✏️
    It's made to be changed. You can add items (.append()), cross things off (.remove()), and even erase and rewrite an item. It's flexible. Use a list for a collection of things that will grow, shrink, or change over time.

  • A Tuple () is a List Carved in Stone. 🗿
    Once you create it, it's permanent. It cannot be changed. You use a tuple for data that represents a single, fixed thing, like RGB color values (255, 100, 50) or a person's first and last name ("John", "Doe"). It's a guarantee that the data won't be accidentally modified.

Practice ✍️

Create a list of your favourite hobbies. Use a for loop to print out a sentence for each one, like "I enjoy [hobby]". Then, add a new hobby to the list using .append() and print the whole list to see the change.

Click to reveal a sample script
# hobbies_list.py
hobbies = ["Reading", "Hiking", "Coding"]

print("My current hobbies are:")
for hobby in hobbies:
    print(f"- I enjoy {hobby}.")

# Let's add a new hobby
new_hobby = "Playing guitar"
hobbies.append(new_hobby)

print("\nI've picked up a new hobby! Now my list is:")
print(hobbies)
        

Day 5: Organising Information with Dictionaries & Sets

Objectives

Lists are great for ordered items, but what if the data has a natural connection, like a word and its definition, or a person and their phone number? For this, we use a dictionary. A dictionary stores key-value pairs. You create them with curly braces {}. For example: contact = {"name": "Jane Doe", "phone": "555-1234"}. Here, "name" is a key, and "Jane Doe" is its value.

You look up values using their key, not an index: contact["phone"] would give you "555-1234". It's super fast! Adding or changing an item is easy: contact["email"] = "jane@example.com". Dictionaries are incredibly useful for organising any kind of structured information, from user profiles to game settings.

Finally, let's talk about sets. A set is also made with curly braces, but it's an unordered collection of unique items. If you add the same item twice, it only gets stored once. This makes sets perfect for two things: quickly removing duplicates from a list, and performing membership tests (checking if an item is in the set). You can also do cool things like find the items that two sets have in common (intersection) or the items that are in one set but not the other (difference).

🤯 Dictionaries & Sets Seem Weird? Here's the Idea.

Let's use real-world examples:

  • A Dictionary {} is a Contact List on Your Phone. 📱
    You don't look someone up by their position (like the 57th person in your contacts). You look them up by their name (the key) to get their phone number (the value). Dictionaries work the exact same way. They connect one piece of information (the key) directly to another (the value).

  • A Set {} is a Collection of Unique Pokémon Cards. 🃏
    The main rule is: no duplicates! If you have a Pikachu card and someone gives you another one, you still only have one *kind* of card: Pikachu. Sets are great for tracking unique things. For example, if you have a set of students in class_A and a set from class_B, you can instantly find which students are in both classes.

Practice ✍️

Create a dictionary to represent a simple user profile with keys for 'name', 'city', and 'favourite_song'. Print a sentence that uses all three values. Then, create two lists of numbers with some duplicates. Convert them to sets to find which numbers appear in both lists.

Click for a sample implementation
# dict_set_examples.py
# Dictionary practice
user_profile = {
    "name": "Alex",
    "city": "Lisbon",
    "favourite_song": "Bohemian Rhapsody"
}

print(f"{user_profile['name']} from {user_profile['city']} loves listening to {user_profile['favourite_song']}.")

# Set practice
list1 = [1, 2, 3, 4, 5, 5]
list2 = [4, 5, 6, 7, 8, 4]

set1 = set(list1)
set2 = set(list2)

print("\nOriginal list 1:", list1)
print("Original list 2:", list2)
# The '&' operator finds the common items (intersection)
common_numbers = set1 & set2
print("Common numbers found in both lists:", common_numbers)
        

Further resources