──────────────────────────────────────

20. Message Lab · Build a Radio Message Cleaner

Normalise a free-text message and produce a consistent radio summary.

Lesson files · lessons/strings-and-messages/radio-message-cleaner

Before you start
- Use split() and join() to rebuild a line of text.
- Use upper() to change the case of letters.
- Choose a message with if and else.

By the end
- Use len() on a list of words to find the word count.
- Use an empty-list check to give blank messages a clear label.
- Test the cleaner with uneven spaces and with only spaces.

Where you can use it
Clean a typed announcement before showing it on a club display. Keep one space between words and show a clear message for an empty announcement.

Read the line, use upper() to change its letters, then use split() to get the words. Use len(words) to count the items in that list. When the list has words, " ".join(words) places one space between each pair.

A line of spaces gives split() an empty list. The condition if words is True only when the list has at least one item. Use its else branch to give an empty message a readable label.

Predict
What list comes from splitting a whitespace-only message?
- A list with one space.
- An empty list.

Worked example (example.py)

words = input().upper().split()
print(" ".join(words))


Example input
 ready   to land 

Example result
READY TO LAND

Clean the message to uppercase with one space between words. Print Words: followed by the word count. Then print Message: followed by one space and the cleaned message. If there are zero words, print Message: (empty) instead.

Starter program (starter.py)

words = input().upper().split()
print(" ".join(words))


Starter input
 ready   to land 

Hint
Use len(words) for the count. Use an if to choose between " ".join(words) and "(empty)".

Case 1. Try the sample
Input
 ready   to land 
Expected output
Words: 3
Message: READY TO LAND

Case 2. Whitespace only
Input
   
Expected output
Words: 0
Message: (empty)

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
Limit a call sign summary to the first four words and explain what the slice does.

Reflect
Which part of the program removes the extra spaces, and which part combines the words?

Check your prediction
An empty list. Default split() removes whitespace separators and returns only the words.
