levo

Problem Solving with Programming

Validation and authentication in Python

  • 3 things to know
  • Paper 2
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Computational Thinking
Data
Computers
Networks

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

The check is 45 + 27 = 72.
denarybinaryhexadecimal

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

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 faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.