Night 16: Name tags
You already finished this night, in Python or pseudocode. It counts for both. Practise again if you like.
Tonight: name tags
- Your pet wants a name tag. Tonight you put values inside text.
- You will learn one thing: f-strings.
Words for tonight
| Word | Meaning |
|---|---|
| f-string | a text with an f in front; values can go inside it |
| braces | the brackets { } |
| space | the empty character between words |
Values inside text
- Put
fbefore the first quote. Then write variable names inside{ }.
name = "Kit"
age = 2
print(f"{name} is {age} years old")
- Python puts each value where its braces are.

Commas or an f-string?
| Code | Output |
|---|---|
print(snack, ":", price) |
apple : 3 |
print(f"{snack}: {price}") |
apple: 3 |
- Commas always add a space. In an f-string you choose the spaces.
Maths inside the braces
- Python works out what is inside
{ }first.
age = 2
print(f"Next year: {age + 1}")
print(f"In dog years: {age * 7}")
Do not forget the f
- Without
f, the braces are just normal text:
name = "Kit"
print("{name} is sleepy")
print(f"{name} is sleepy")
- Now make some name tags!
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Read a name, then an age with int(input()). Use an f-string to print Kit is 2 years old.
Click Run to see the output here.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Read a snack and a price. Print a price tag like apple: 3 coins. There is no space before the :.
Click Run to see the output here.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Read a name and an age. Print Next year Kit is 3. Work out age + 1 inside the { }.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Read a name, a kind and a number of nights. Print a 3-line card: Name: Kit, then Kind: fox, then Nights: 12/30.
Click Run to see the output here.