← ACARA Digital Technologies Years 9–10

Testing letters with isalpha() and isupper()

Returns True if the character ch is a letter, so a Caesar loop can shift letters and leave spaces and punctuation unchanged. ch.isupper() checks for capitals.

Understanding Testing letters with isalpha() and isupper() in ACARA Digital Technologies Years 9–10

What it does: The if statement runs the shifting code only when isalpha() is True. Spaces and punctuation skip it and are left as they are. isalpha() is a string method, so you call it with a dot after the character: ch.isalpha(). It returns True or False, so it works directly in an if. isupper() checks for capitals only. 'G'.isupper() is True, but 'g'.isupper() is False even though both are letters. isalpha() is the test a Caesar loop uses to decide whether a character is a letter that should be shifted.

Common mistakes: A for loop header must end with a colon. It should be: for ch in message:. isalpha is a method, so it needs brackets to run. Without them Python just checks that the method exists, so the test always passes. It should be: if ch.isalpha():.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 860–875) and word search (Modules 860–944).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A Caesar loop reads the character ' ' (a space). What does ' '.isalpha() return?
True, so the space is shiftedFalse, so the space is left unchanged
Matches
if ch.isalpha:
↓
The brackets are missing, so Python checks the method itself and not its result. It must be ch.isalpha().
Applying
Meanings
Term
ch.isalpha()
Meaning
Returns True if the character ch is a letter, so a Caesar loop can shift letters and leave spaces and punctuation unchanged. ch.isupper() checks for capitals.
Practice
message = "Hi, Zoe!"
Testing
Gaps
if ch.():
Check Answer
Spots
1for ch in message
2 if ch.isalpha():

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Reef Shark' badge — Reef Ruler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A Caesar loop reads the character ' ' (a space). What does ' '.isalpha() return?
A. False, so the space is left unchanged ✓
B. True, so the space is shifted
isalpha() is True only for letters. A space is not a letter, so the loop skips it and keeps it as it is.
2. Which line correctly tests whether the character ch is a letter?
A. if ch.isalpha(): ✓
B. if isalpha(ch) == ch:
isalpha() is a string method, so you call it with a dot after the character: ch.isalpha(). It returns True or False, so it works directly in an if.
3. What does '!'.isalpha() return in Python?
A. False ✓
B. True
Punctuation such as ! , . and ? is not a letter, so isalpha() returns False. A Caesar loop leaves these characters alone.
4. Why does a Caesar encryption loop check ch.isalpha() before shifting?
A. So the loop shifts every character, including spaces
B. So only letters are shifted and spaces and punctuation stay the same ✓
Shifting a space or a comma would produce strange symbols and break the message. The isalpha() test makes sure only letters change.
5. Which character makes 'G'.isupper() return True?
A. G is a letter, so isupper() always returns True for any letter
B. G is a capital letter, so it returns True ✓
isupper() checks for capitals only. 'G'.isupper() is True, but 'g'.isupper() is False even though both are letters.

Match the Pairs

ch.isalpha() → Returns True if the character ch is a letter, and False for spaces, digits and punctuation
ch.isupper() → Returns True if the letter ch is a capital letter, so the loop knows whether to shift from 'A' or from 'a'
Only shift a character if it is a letter, so spaces and punctuation stay unchanged → if ch.isalpha():
Leave a character unchanged when it is not a letter by adding it to the result as it is → else: result += ch
if ch.isalpha: → The brackets are missing, so Python checks the method itself and not its result. It must be ch.isalpha().
if isalpha(ch): → isalpha() is a string method, so it is written after the character with a dot. It must be ch.isalpha().

Key Term

ch.isalpha()
Returns True if the character ch is a letter, so a Caesar loop can shift letters and leave spaces and punctuation unchanged. ch.isupper() checks for capitals.

Fill in the Blanks

1. for ch in message: if ch.isalpha(): result += ch
Hint: Type the string method that checks whether a character is a letter.
2. for ch in message: if ch.isalpha(): shift = 3
Hint: Type the keyword that starts a condition so only letters get shifted.
3. ch = 'q' print(ch.isupper()) # prints False
Hint: Type the method that checks whether a letter is a capital.
4. if not ch.isalpha(): result += ch continue
Hint: Type the keyword that reverses the test so spaces and punctuation are caught and left unchanged.
5. base = 65 if ch.isupper() else 97
Hint: Type the ASCII code of the first lowercase letter, used as the base for lowercase letters.

Spot the Error

Question 1
A for ch in message
B if ch.isalpha():
C result += ch
Line A — A for loop header must end with a colon. It should be: for ch in message:
Question 2
A for ch in text:
B if ch.isalpha:
C print(ch, 'letter')
Line B — isalpha is a method, so it needs brackets to run. Without them Python just checks that the method exists, so the test always passes. It should be: if ch.isalpha():
Question 3
A result = ''
B for ch of text:
C if ch.isalpha():
D result += ch
Line B — Python loops use the keyword in, not of. It should be: for ch in text:
Question 4
A word = 'Hello'
B if word[0].isUpper():
C print('Capital start')
Line B — Python method names are case-sensitive. The method is isupper() with all lowercase letters, not isUpper().
Question 5
A result = ''
B for ch in text:
C if ch.isalpha():
D result = shift(ch)
E else:
F result += ch
Line D — Using = replaces result each time, so only the last character is kept. It should be result += shift(ch) to add to the message.

Student with a class code? Join your class →