Input/Output & f-strings

So far, every value in your programs has been typed directly into the code. Today your programs start listening: input() lets a person type something back, and f-strings are the clean way to weave that — or any variable — into a sentence.

What You'll Learn

  • input("prompt") — pauses your program, shows the prompt, and waits for the player to type something and hit Enter
  • f-strings — put an f before the opening quote and wrap variables in { } to drop them straight into a sentence
  • Type conversion — input() always hands back a string, so wrap it in int() or float() when you need a number
Watch out for: input() always returns a string, even if the player types 100. Add two un-converted inputs together and you'll get "10" + "5" → "105" instead of 15 — convert numeric input the moment you read it.

Today's Activity

Today's practice happens inside the notebook below — work through it top to bottom:

  1. A worked example, fully written out
  2. Two guided practices — change a few values, then fill in some blanks
  3. Two independent practices — write your own from scratch, different scenario each time
  4. An optional stretch, if you want to go further
  5. One check-your-understanding question to close

Download the notebook, save it into your 1_foundations folder in your cloned repo, and open it in VS Code. Commit once you've saved it, then commit again when you're done for the day.

Download 1.2_Input_Output_and_Fstrings.ipynb

New to notebooks? See Using Jupyter Notebooks first.

What's Next

Coming up: 1.3 — Operators & Expressions, where you start actually calculating things.