Back to the topic

The mark scheme starts on a new page, so you can print pages one and two for a student and keep the last page yourself. Everything prints in black on white whichever theme you are using.

Python · GCSE 4

Validation, Authentication and Testing

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 19 marks. Total 29 marks.

Name

Class

Date

Mark  / 29

Section A

Circle the letter of the correct answer. One mark each.

  1. 1What does validation check?1
    1. AThat the program has no bugs
    2. BThat data is true
    3. CThat the user is who they claim to be
    4. DThat data is reasonable and allowed
  2. 2Which validation check is len(password) >= 8?1
    1. AA presence check
    2. BA range check
    3. CA lookup check
    4. DA length check
  3. 3Which check makes sure something has been entered at all?1
    1. AA lookup check
    2. BA presence check
    3. CA format check
    4. DA range check
  4. 4A program accepts whole numbers from 1 to 10. Which value is boundary test data?1
    1. A10
    2. B5
    3. C-3
    4. Dten
  5. 5A program expects a whole number from 1 to 10. Which is erroneous test data?1
    1. A10
    2. B5
    3. C"ten"
    4. D11
  6. 6What is the difference between validation and verification?1
    1. AValidation checks data was entered as intended, verification checks it is reasonable
    2. BVerification checks data was entered as intended, validation checks it is reasonable
    3. CValidation checks the data type and verification checks the data range
    4. DValidation is done by the user and verification is done by the program
  7. 7What is authentication?1
    1. ATesting a program
    2. BRemoving spaces from input
    3. CProving the identity of a user
    4. DChecking that a number is in range
  8. 8What is a logic error?1
    1. AThe program has no comments
    2. BThe program crashes on a certain line
    3. CThe program runs but gives the wrong result
    4. DThe program will not start
  9. 9When does iterative testing take place?1
    1. ADuring development, as each part is finished
    2. BOnly before any code is written
    3. COnly once the whole program is finished
    4. DOnly by the end user
  10. 10Which of these makes code easier to maintain?1
    1. APutting everything in one long block
    2. BMeaningful variable names and comments
    3. CRemoving all indentation
    4. DSingle letter variable names

Section B

Answer in the space provided. The number of marks tells you how many separate points to make.

  1. 1ExplainExplain the difference between validation and verification.3
  2. 2WriteWrite a Python function called good_password that takes a password and returns True if it is at least 8 characters long and contains at least one digit, and False otherwise.4
  3. 3GiveA program asks the user to enter their test mark, which must be a whole number from 0 to 100 inclusive. Give one item of normal data, one item of boundary data, one item of invalid data and one item of erroneous data that could be used to test it. State whether each should be accepted.4
  4. 4DescribeA login system gives users three attempts to enter the correct password. Describe two other ways that the system could be made more secure.4
  5. 5ExplainThe program shown works but is difficult to maintain. Explain two changes that would make it easier to maintain.4
    Python
    def f(a,b):
        c=a*b*0.2
        return c
    x=f(50,2)
    print(x)

Mark scheme

Section A

1D2D3B4A5C6B7C8C9A10B

Section B

1 Explain the difference between validation and verification. 3

One mark for each of the following, to a maximum of 3.

  • Validation checks that data is reasonable or allowed
  • Verification checks that data was entered as the user intended
  • Validation cannot tell whether the data is actually correct

Model answer. Validation is an automatic check that the data entered is reasonable and allowed, such as a number being in range, but it cannot tell if the data is actually correct, because a wrong age that is still between 0 and 120 will pass. Verification checks that the data was entered as the user intended, for example by asking for a password to be typed twice and comparing the two.

2 Write a Python function called good_password that takes a password and returns True if it is at least 8 characters long and contains at least one digit, and False otherwise. 4

One mark for each of the following, to a maximum of 4.

  • Defines a function with a parameter for the password
  • Checks the length is 8 or more using len
  • Loops through the characters checking for a digit, such as with isdigit
  • Returns True only when both conditions are met

Model answer.

Python
def good_password(password):
    has_digit = False
    for ch in password:
        if ch.isdigit():
            has_digit = True
    return len(password) >= 8 and has_digit

print(good_password("Tr1angle!"), good_password("password"), good_password("a1"))

The loop sets a flag if any character is a digit. The function returns True only when the length check and the digit check are both true. The calls shown print True False False.

3 A program asks the user to enter their test mark, which must be a whole number from 0 to 100 inclusive. Give one item of normal data, one item of boundary data, one item of invalid data and one item of erroneous data that could be used to test it. State whether each should be accepted. 4

One mark for each of the following, to a maximum of 4.

  • Normal data accepted, such as 50
  • Boundary data such as 0 or 100 accepted, or 101 or -1 rejected
  • Invalid data such as 150 or -20 rejected
  • Erroneous data such as a word or a decimal rejected

Model answer. Normal data, for example 50, should be accepted. Boundary data is on the edge of the range: 0 or 100 should be accepted, and the values just outside, -1 or 101, should be rejected. Invalid data is a whole number outside the range, such as 150, and should be rejected. Erroneous data is the wrong type altogether, such as the word ten or the decimal 7.5, and should be rejected.

4 A login system gives users three attempts to enter the correct password. Describe two other ways that the system could be made more secure. 4

One mark for each of the following, to a maximum of 4.

  • Two factor authentication such as a code sent to a phone
  • Explains that a stolen password alone is then not enough
  • Rules for password strength such as minimum length, digits or capitals
  • Explains that stronger passwords are harder to guess

Model answer. Two factor authentication asks for something in addition to the password, such as a code sent to the user's phone, so a person who has stolen or guessed the password still cannot log in without the second device. Enforcing password rules, such as a minimum length and a mix of capitals, digits and symbols, makes the password much harder to guess or to crack by trying many combinations.

5 The program shown works but is difficult to maintain. Explain two changes that would make it easier to maintain. 4

One mark for each of the following, to a maximum of 4.

  • Use meaningful names for the function, parameters and variables
  • So that another programmer can tell what each one is for
  • Replace 0.2 with a named constant, or add comments and white space
  • So the value is only changed in one place, or the reader knows why the code is there

Model answer. The names f, a, b, c and x say nothing about what the program does, so they should be replaced with meaningful names such as calculate_vat, price, quantity and vat, so another programmer can tell what each is for without working it out. The number 0.2 is unexplained, so it should be stored in a named constant such as VAT_RATE, which explains it and means it only has to be changed in one place if the tax rate changes. Comments and white space around the operators would also make the code easier to follow.