Input/output unit 2 Flashcards
(10 cards)
Why is validation needed?
To ensure that user input or data from a file is reasonable, even if it’s not guaranteed to be correct.
What is a range check?
A check that ensures data is within a specified minimum and maximum value.
What is a length check?
A check that ensures input is not too short or too long.
What is a presence check?
A check that ensures the user has entered something, not left it blank.
What should you do if a user must choose from a list of options?
Validate their input to make sure it matches a valid choice from the list.
How do programs respond to user input?
By using if statements or loops to check and react to what the user entered.
Why are text files used in programs?
To store data so it can be saved even after the program closes, and used again later.
What does writing to a text file do?
It saves data from the program into a file on disk.
What does reading from a text file do?
It loads data from a file into the program for use.
Give an example of input validation in Python.
age = int(input(“Enter your age: “))
while age < 0 or age > 120:
age = int(input(“Invalid. Enter your age: “))