Engineering Python · Language Basics
Input and Output
In Engineering Python because labs format results for humans and take simple values as inputs — even when the browser supplies them as variables.
`print` formats output; f-strings embed expressions in text. Real `input()` waits for a typed line — awkward in some in-browser runtimes — so labs here often bind the 'input' to a variable and say so honestly. The skill is the same: read a value, compute, format the result.
- Engineering Python
- Easy level
- 4 concepts
1Formatting output
f-strings embed expressions inside `{}` in a string: `f"n={n}"`.
Prefer clear labels in printed lines so lab checks and humans can find the number.
Figure. f-strings embed expressions inside {} in a string. Prefer a labelled printed line.
f-string
n = 3
print(f"count={n}")What does an f-string let you do?
- Embed expressions inside a string with {}
- Delete variables
- Import numpy
f-strings interpolate expressions into text.
2Reading simple values
In a desktop REPL, `input("prompt")` returns a string the user typed. Cast it before arithmetic.
In this course's browser labs, we usually set `raw = "..."` ourselves instead of calling `input()`, because the notebook runtime may not offer a typed prompt. Treat that variable as the input.
Figure. Desktop input() returns a typed string. Browser labs usually bind raw themselves because the notebook may not offer a prompt. Cast before arithmetic.
Takeaway
- IdeaIn a desktop REPL, `input("prompt")` returns a string the user typed. Cast it before arithmetic.
3Read → compute → print
The I/O pattern is: obtain a value (variable or input), convert if needed, compute, print a labelled result.
Labs grade the printed line — a bare number with no label is harder to check and harder for humans to read.
Figure. The I/O pattern is: obtain a value, convert if needed, compute, print a labelled result.
I/O pattern
- ObtainBind the raw value (simulated input or real input).
- ConvertCast to the type arithmetic needs.
- ReportPrint a labelled result.
In a lab that checks stdout, why print `doubled=8` instead of bare `8`?
- A labelled line is easy to spot for humans and stdout checks
- Bare numbers cannot be printed
- Labels disable type errors
Labels make the result searchable and readable.
4Lab: simulate input via a variable
Pretend `raw` came from the user. Cast, double, and print a labelled line.
Figure. Treat raw as user input. Cast to int, double it, and print a line containing doubled=8.
Takeaway
- IdeaPretend `raw` came from the user. Cast, double, and print a labelled line.
Coding lab. Simulate input runs in the app, with checks on your output.
Notes
- In Engineering Python because labs format results for humans and take simple values as inputs — even when the browser supplies them as variables.
- f-strings embed expressions inside `{}` in a string: `f"n={n}"`.
- In a desktop REPL, `input("prompt")` returns a string the user typed. Cast it before arithmetic.
Exam traps & shortcuts
- Run one cell at a time and read stdout before changing more lines.
- Names are labels for values; rebinding a name does not rewrite old prints.
Recap
Format with f-strings; simulate input as a variable when the runtime has no prompt.
- Formatting output
- f-strings embed expressions inside `{}` in a string: `f"n={n}"`.
- Reading simple values
- In a desktop REPL, `input("prompt")` returns a string the user typed. Cast it before arithmetic.
- Read → compute → print
- The I/O pattern is: obtain a value (variable or input), convert if needed, compute, print a labelled result.
- Lab: simulate input via a variable
- Pretend `raw` came from the user. Cast, double, and print a labelled line.
Practise Input and Output
Reading is free and needs no account. Practice, mocks and progress live in the app.
- A 2-question practice set that ends the chapter
- 2 quick checks with worked explanations
- Timed mocks scored with the real marking scheme
- Readiness tracked per topic, kept on your device