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

5. The Club Pass Desk · Make a Message Personal

Supply a line of input and tidy the text before using it.

Lesson files · lessons/input-and-decisions/text-and-input

Before you start
- Store text under a name.
- Put a name inside an f-string.

By the end
- Use input() to read a line while the program runs.
- Use strip() to trim the ends of a line.
- Explain why spaces between words stay in the greeting.

Where you can use it
Ask a player for their name when a game starts. Trim stray spaces before showing their name on a welcome screen.

input() reads one line and returns text. In Studio, enter the line in Program input before you run. In a local terminal, type the line when the program waits and press Enter.

Add .strip() to trim whitespace such as spaces and tabs from the two ends of the line. Spaces inside the name stay in place. Try a two-word name with extra spaces at the ends.

Predict
Where do the spaces around River go?
- strip() trims them.
- They stay in the greeting.

Worked example (example.py)

name = input().strip()
print(f"Hello, {name}!")


Example input
  River  

Example result
Hello, River!

Read the team name, trim it and print Team: followed by one space and the cleaned name.

Starter program (starter.py)

name = input().strip()
print(f"Hello, {name}!")


Starter input
  River  

Hint
Use input().strip() to get the name. In the f-string change the greeting text and remove the exclamation mark.

Case 1. Try the sample
Input
  Comets  
Expected output
Team: Comets

Case 2. Trims both ends
Input
 Night Owls 
Expected output
Team: Night Owls

Stretch
Read a second line with a mascot name, then print the team and mascot in one sentence.

Reflect
What would you see if you left out strip()?

Check your prediction
strip() trims them. strip() removes leading and trailing whitespace from the value it returns.
