×

python · level 1 · unit 3 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

An fills in the gaps in your text.

Put an f before the opening quote and you get an f-string. Anything inside curly brackets {} is swapped for its value, like filling in the gaps on a birthday card.

Remember, input() always gives back text. To do maths with it, it first. int() turns text like "12" into the number 12, and str() turns a number back into text.

You can wrap one inside the other. int(input("Age? ")) asks the question and converts the answer in one go.

name = "Sam"
age = 9
print(f"Happy birthday, {name}! You are {age}.")
print(f"Next year you will be {age + 1}.")
print("Candles: " + str(age))

int() only works on text that looks like a whole number, so int("cake") gives an error.