levo

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.

Your recallNot started
Key term

Define validation.

Key term

Why do programs validate input?

Key term

What is a presence check, and how is one written in Python?

Questions from this subtopic

Each one with the model answer underneath.

  1. 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. 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. 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. 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. 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. 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.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Computational Thinking
Data
Computers
Networks

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

The check is 45 + 27 = 72.
denarybinaryhexadecimal

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AA normal test value is 14.
BA boundary test value is 16.
CAn erroneous test value is 20.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

A kibibyte (KiB) is 1,024 bytes. The figure 1,024 is 2¹⁰.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

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.