๐ŸŸข LESSON 01 ยท FULL SCAFFOLD

File Recap & First Strings

We revisit opening, reading, and writing files โ€” then meet our first string functions: upper() and lower(). All code is provided โ€” copy it, run it, and experiment!

๐ŸŸข Full code provided โ€” just copy, run, and explore in IDLE

๐ŸŽฏ Learning Objectives

๐Ÿƒ Match the Terms ACTIVITY 1

Click a term on the left, then click its matching definition on the right.

Matched: 0 / 5
open()
.upper()
.lower()
for loop
.write()
Returns a copy of the string in all lowercase letters
Opens a file and returns a file object to work with
Sends text to an open file
Repeats a block of code for each item in a sequence
Returns a copy of the string in ALL CAPITAL letters

๐Ÿ’ป Your First Program ACTIVITY 2
๐Ÿ“ Before you start: Open Notepad and create a file called input.txt. Save it in the same folder where you will save your Python file. Copy the text below and paste it into Notepad, then save the file:
TEXT โ€” input.txt
My Name Is Alex
i love coding in python
GCSE Computer Science Is Fun
hello World
The Quick Brown Fox
jersey is a BEAUTIFUL island
๐Ÿ“‹ Instructions: Copy the code below into IDLE (File โ†’ New File), save it as lesson1.py in the same folder as your input.txt. Run it with F5. Check the output.txt file that is created!
Python โ€” lesson1.py
# ============================================
# Lesson 1 โ€” File Recap & String Case
# ============================================

# --- STEP 1: Open the input file for reading ---
input_file = open("input.txt", "r")

# --- STEP 2: Open the output file for writing ---
output_file = open("output.txt", "w")

# --- STEP 3: Loop through every line in the input file ---
for line in input_file:

    # Remove the newline character from the end of each line
    line = line.strip()

    # Convert the line to UPPER CASE
    upper_line = line.upper()

    # Convert the line to lower case
    lower_line = line.lower()

    # Print both versions to the screen
    print("UPPER:", upper_line)
    print("lower:", lower_line)

    # Write the upper case version to the output file
    output_file.write(upper_line + "\n")

# --- STEP 4: Close both files ---
input_file.close()
output_file.close()

print("\nโœ… Done! Check your output.txt file.")
๐Ÿ”ฌ Now Experiment! CHALLENGES

โœ๏ธ Fill in the Blanks ACTIVITY 3

Complete the code below by typing in the missing parts. Press Check when done.

# Open the input file my_file =

for line in my_file:
    line = line.  # clean whitespace
    result = line.  # make ALL CAPS
    print(result)

my_file.

๐Ÿง  Quick Quiz ACTIVITY 4
What does "Hello World".upper() return?
Hello World
hello world
HELLO WORLD
Hello WORLD
Which mode string do you use to open a file for writing?
"r"
"w"
"x"
"write"
If name = "Python", what is the value of name after name.lower()?
"python"
"Python" โ€” strings are immutable, lower() returns a new string
"PYTHON"
An error occurs
What is the purpose of .strip() when reading file lines?
It removes all vowels from the string
It removes whitespace and newline characters from both ends
It deletes the line from the file
It converts the line to a list

๐Ÿ”ฎ Predict the Output ACTIVITY 5

Look at each code snippet and predict what will be printed. Click to reveal the answer!

What does this print?
word = "Python"
print(word.upper())
print(word)
PYTHON
PYTHON
PYTHON
Python
python
Python
An error
What does this print?
text = "Hello World"
result = text.lower()
print(result)
Hello World
hello world
HELLO WORLD
Hello world
What does this print?
name = "jersey"
name.upper()
print(name)
JERSEY
jersey
Jersey
An error

๐ŸŽฎ Memory Game ACTIVITY 6

Match each function to its description. Click two cards to flip them!

Moves: 0Pairs: 0/4

๐Ÿš€ Extension Activity STRETCH
Challenge: Title Case Converter

Modify your program so that instead of converting lines to upper or lower case, it converts them to title case (first letter of each word capitalised).

Steps:
1. Read each line from input.txt
2. Use Python's .title() method to convert to title case
3. Write the original line AND the title case version to output.txt
4. At the end, print how many lines were processed

Extra challenge: Also write the swapcase version using .swapcase() โ€” what does it do? Find out!
โ† Back to Lessons Lesson 2: Length & Indexing โ†’