In & Out
Every program takes something in and sends something out. Learn how to read user input, convert and validate it, handle a login, and read data from a CSV file in the right order.
Revise this, the fun way
Play it interactively, earn XP and build a streak, free.
Start revising freeWhat you'll cover
Talking to a program 💬
Every useful program takes something **in**, does some work, then sends something **out**. Reading data from the user is **input**; showing a result is **output**. Getting this right is the start of every program.
Words to know 🔑
Four ideas run through input and output:
String or number? ⚖️
Input usually arrives as text, even when it looks like a number.
Why convert? 🎯
Why must a number typed by the user usually be converted before a calculation?
- It is read in as a string, not a number
- Numbers are too slow to use directly
- To keep the number secret
- To change its colour on screen
Match the check 🔗
- Length check
- Presence check
- Range check
- Pattern check
- Makes sure a password is long enough
- Makes sure a field is not left empty
- Makes sure a value is between two limits
- Makes sure input follows a set format
Who goes there? 💡
Many programs need to check who you are. A simple authentication routine asks for an ID and a password, then looks them up in a stored list. If both match a record you are let in; if not, access is refused. Passwords should never be shown on screen as they are typed.
Trace the input 📊
An interactive activity.
Kinds of validation ✅
Which THREE are types of input validation?
- A length check
- A range check
- A presence check
- A colour check
- A volume check
Reading a CSV 🪜
An interactive activity.
Complete the idea 🧩
A program uses _____ to read from the user and _____ to show a result. Because input arrives as a _____, it is _____ to a number before any calculation. Before using the value, the program should _____ it to check it is sensible.
True or not? 🖍️
An interactive activity.
Match the term 🔀
- Input
- Output
- Cast
- Authenticate
- Read data into the program
- Send a result out to the user
- Convert a string into a number
- Check an ID and password to allow access
Which check? 🧭
An interactive activity.
Explain input and output ✍️
An interactive activity.