HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /This is the kind of long scenario question that ends Paper 2…
HardComputer ScienceHigh School (9–10)Computer Science › Algorithms and Problem-SolvingcodingConceptualIGCSE

This is the kind of long scenario question that ends Paper 2…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

This is the kind of long scenario question that ends Paper 2. Answer in pseudocode.

A website asks a new user for a username, an age and a password. Write an algorithm that:

  • uses a length check: the username must have 666 to 121212 characters;
  • uses a range check: the age must be from 131313 to 999999;
  • uses a double entry check: the password is typed twice and the two must match;
  • repeats each input, with a helpful message, until it passes;
  • welcomes the user by username at the end.

Then dry-run it for the inputs sam, samirak, 121212, 151515, sun, son, moon42, moon42. How many error messages are output, and how many inputs are taken?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

Validation checks that data is sensible: range, length, type, presence and format checks, and a check digit. Verification checks that data was entered as intended: a visual check and a double entry check. A validation loop repeats the input, with an error message, until the data is acceptable.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

A model answer.

pseudocode
// Sign-up checks
REPEAT
    OUTPUT "Enter a username (6 to 12 characters)"
    INPUT Username
    IF LENGTH(Username) < 6 OR LENGTH(Username) > 12
      THEN
        OUTPUT "Username must have 6 to 12 characters"
    ENDIF
UNTIL LENGTH(Username) >= 6 AND LENGTH(Username) <= 12
REPEAT
    OUTPUT "Enter your age"
    INPUT Age
    IF Age < 13 OR Age > 99
      THEN
        OUTPUT "Age must be 13 to 99"
    ENDIF
UNTIL Age >= 13 AND Age <= 99
REPEAT
    OUTPUT "Enter a password"
    INPUT Password
    OUTPUT "Enter the password again"
    INPUT Again
    IF Password <> Again
      THEN
        OUTPUT "The two passwords do not match"
    ENDIF
UNTIL Password = Again
OUTPUT "Welcome, ", Username

The run.

  • sam has 333 characters: message 111. samirak has 777: accepted.
  • 121212 is below 131313: message 222. 151515: accepted.
  • sun and son differ: message 333. moon42 and moon42 match: accepted.
  • Output: Welcome, samirak.

That is 333 error messages and 2+2+4=82 + 2 + 4 = 82+2+4=8 inputs.

A marking list. One mark for each point.

  1. A prompt before the username.
  2. A loop that repeats the username input.
  3. LENGTH used for the username.
  4. Both limits, 666 and 121212, included correctly.
  5. A message for a username of the wrong length.
  6. A prompt before the age.
  7. A loop that repeats the age input.
  8. Both limits, 131313 and 999999, included correctly.
  9. A message for an age out of range.
  10. The password is input.
  11. The password is input a second time.
  12. The two passwords are compared with <> or =.
  13. A message when they do not match, and both are entered again.
  14. The welcome message with the username.
  15. Meaningful names and comments.

Answer: 333 error messages and 888 inputs.

What if? The age box could also have a type check, so that text such as fifteen is refused before the range check.

Log in to save this for later
← All Problems
← A delivery company adds a check digit to each parcel number…A school library keeps a record for each book… →
More onComputer Science › Algorithms and Problem-Solving

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Validation and verificationStandard Algorithms: Totals, Searching, Sorting and Validation

More on this topic

  1. A delivery company adds a check digit to each parcel number…Medium
  2. Name the check in each case. Say whether it is validation or verification…Easy
  3. A bubble sort is changed so that it sorts in descending order: the comparison becomes IF…Hard
A shop stores the colours of the ten bicycles in its window in an array Colours: red, blue, red…Medium
  • A bubble sort puts the scores 5, 1, 4, 2, 8 into ascending order…Medium
  • All problems on this topic →