Edexcel GCSE Computer Science 1CP2
Computational Thinking
Data
Computers
Networks
Issues and Impact
Problem Solving with Programming
Problem Solving with Programming
Validation and authentication in Python
- 3 things to know
- Paper 2
Overview
Presence, length, range and pattern checks written in Python, validation loops, checking digits before conversion, and authentication by ID, password and lookup.
What you need to know
Answer each one before you reveal it.
Why do programs validate input?
What is a presence check, and how is one written in Python?
Questions from this subtopic
Each one with the model answer underneath.
- 1
Define validation.
Model answer
Validation checks that input is sensible and allowed before a program uses it. Validation cannot prove the data is correct, only that it is reasonable.
- 2
Why do programs validate input?
Model answer
Invalid input can crash a program or produce wrong results. Validation stops bad data at the point of entry.
- 3
What is a presence check, and how is one written in Python?
Model answer
A presence check makes sure something has been entered. The condition name == "" is True when the entry has been left empty.
- 4
What does a length check do, and which Python function does it use?
Model answer
A length check makes sure the number of characters is within set limits. The len() function supplies the count, as in len(password) >= 8.
- 5
What is a range check, and how is one written in Python?
Model answer
A range check makes sure a number lies between a lowest and a highest allowed value. The condition score >= 0 and score <= 100 checks a percentage.
- 6
Describe a pattern check.
Model answer
A pattern check makes sure input follows a set format, such as two letters then four digits. The string methods isalpha() and isdigit() can test each part.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Problem Solving with Programming, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.