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
fbefore 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 inint()orfloat()when you need a number
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:
- A worked example, fully written out
- Two guided practices — change a few values, then fill in some blanks
- Two independent practices — write your own from scratch, different scenario each time
- An optional stretch, if you want to go further
- 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.
New to notebooks? See Using Jupyter Notebooks first.
What's Next
Coming up: 1.3 — Operators & Expressions, where you start actually calculating things.