Input/output unit 2 Flashcards

(10 cards)

1
Q

Why is validation needed?

A

To ensure that user input or data from a file is reasonable, even if it’s not guaranteed to be correct.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a range check?

A

A check that ensures data is within a specified minimum and maximum value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a length check?

A

A check that ensures input is not too short or too long.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a presence check?

A

A check that ensures the user has entered something, not left it blank.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What should you do if a user must choose from a list of options?

A

Validate their input to make sure it matches a valid choice from the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do programs respond to user input?

A

By using if statements or loops to check and react to what the user entered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why are text files used in programs?

A

To store data so it can be saved even after the program closes, and used again later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does writing to a text file do?

A

It saves data from the program into a file on disk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does reading from a text file do?

A

It loads data from a file into the program for use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give an example of input validation in Python.

A

age = int(input(“Enter your age: “))
while age < 0 or age > 120:
age = int(input(“Invalid. Enter your age: “))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly