Pearson Edexcel 1CP2 GCSE Computer Science · Topic 6: Problem Solving with Programming

Stretch tasks Developing and Testing Programs

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

This or That

Pixel the cat asks 8 questions. Each has two answers: pick the right one.

  • Two answers to every question
  • A fish treat for every right answer
  • Streaks win Pixel shades, then a party hat

About 4 minutes

Task 3

Memory Match

Flip the cards two at a time to match each term card to its meaning card.

  • 12 cards: each term has a meaning
  • One peek at every card
  • Combo points for pairs found in a row

6 pairs, about 4 minutes

Task 4

Sort It

Sort each statement into the right box, like the tick-box tables in the exam.

  • 12 cards to sort into 3 boxes
  • Drag a card, tap a box or press its number
  • Combo points for cards sorted in a row

12 cards, about 4 minutes

The games need JavaScript. Every question is below, with the answers at the end.

Read the lesson: Developing and Testing Programs

Developing and Testing Programs: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. What is the difference between a procedure and a function?

    • Procedures cannot be called
    • A function returns a value
    • A procedure returns a value
    • Only functions take parameters
  2. In this code, what are 4 and 7?

    def area(width, height):
        return width * height
    
    size = area(4, 7)
    • Arguments
    • Parameters
    • Constants
    • Local variables
  3. What does tally() return the third time it is called?

    def tally():
        count = 0
        count = count + 1
        return count

  4. Which validation check is if 0 <= mark <= 100:?

    • Range check
    • Presence check
    • Length check
    • Format check
  5. Which validation check is if "@" in email:?

    • Format check
    • Range check
    • Type check
    • Look up check
  6. Validation checks that data is true.

    • True
    • False
  7. What does authentication check?

    • That files exist
    • That users are who they claim to be
    • That data is in range
    • That the code has no syntax errors
  8. A missing colon stops the program running at all. Which error is this?

    • Syntax error
    • Logic error
    • Runtime error
    • Validation error
  9. A program runs but gives the wrong total. Which error is this?

    • Authentication error
    • Logic error
    • Syntax error
    • Runtime error
  10. Dividing by zero stops a running program. Which kind of error is this?

  11. For a mark from 0 to 100, which TWO are boundary test data?

    Tick 2.

    • cat
    • 3.5
    • 100
    • 101
    • 55
  12. Why are local variables the right default?

    • They last for ever
    • They are visible everywhere
    • Subprograms cannot interfere with each other's variables
    • They run faster

Quiz Challenge, round 2: Quick Fire

  1. Explain the difference between validation and authentication. [2 marks]

  2. Explain why boundary test data is important. [2 marks]

  3. Explain why this function returns 1 every time it is called, and how to make it count. [2 marks]

    def tally():
        count = 0
        count = count + 1
        return count

  4. Give two features of maintainable code and explain how each helps. [2 marks]

Quiz Challenge, round 3: Big Think

  1. Write a Python validation loop that keeps asking for a mark until a whole number between 0 and 100 is entered, and describe the test data you would use to test it. [6 marks]

  2. A team writes a long program as one block of code with variables called x, y2 and tmp. Explain how they could improve it using subprograms and good coding practice, and the benefits of each change. [6 marks]

This or That: tick the right answer

  1. def greet(name): print("Hello", name). Procedure or function?

    • Procedure
    • Function
  2. In def area(width, height), what are width and height?

    • Arguments
    • Parameters
  3. The program crashes because a file is missing. Which error?

    • Syntax error
    • Runtime error
  4. Using + where - was meant: which error?

    • Logic error
    • Syntax error
  5. For a mark from 0 to 100, which kind of test data is 101?

    • Normal
    • Boundary
  6. "cat" entered as a mark is which kind of test data?

    • Erroneous
    • Boundary
  7. Can validation prove a date of birth is true?

    • No: only that it is reasonable
    • Yes: that is its job
  8. Should count = count + 1 have a comment saying 'adds one'?

    • Yes: every line needs one
    • No: explain why instead

Memory Match: match each term to its meaning

TermMeaning
A Parameter1 Breaks the language's rules, so it will not run
B Argument2 Stops the program while it is running
C Local variable3 Runs, but gives the wrong result
D Syntax error4 Exists only while its subprogram runs
E Logic error5 Value passed in when called
F Runtime error6 Name in a subprogram's definition

Sort It: tick one box in each row

Syntax, logic or runtime? Sort each error.

StatementSyntax errorLogic errorRuntime error
Dividing by zero
An index out of range
A missing quotation mark at the end of a string
Using < where <= was meant
Using + where - was meant
A missing colon after if
Opening a file that does not exist
An unclosed bracket
Calling int("cat")
Dividing a total by the wrong count
A loop that adds the first item twice
Indentation that breaks a block
Answers

Round 1: Quiz Blitz

  1. A function returns a value Python uses def for both.
  2. Arguments Parameters are the names in the definition. Arguments are the values passed in.
  3. 1 count is local, so it starts at 0 on every call.
  4. Range check It tests that the value lies between limits.
  5. Format check It checks the entry matches a required pattern.
  6. False It checks that data is reasonable. A plausible but wrong date still passes.
  7. That users are who they claim to be Usually with a username and password.
  8. Syntax error It breaks the rules of Python, and is reported with a line number.
  9. Logic error Nothing reports a logic error, which is why they are expensive.
  10. runtime The program starts, then stops.
  11. 100; 101 Boundaries are tested on both sides: 0 and 100, and -1 and 101.
  12. Subprograms cannot interfere with each other's variables Two subprograms can each use a variable called i safely.

Round 2: Quick Fire

    • Validation checks that data is reasonable
    • Authentication checks that users are who they claim to be
    Model answer

    Validation checks that the data entered is reasonable, such as a mark between 0 and 100. Authentication checks that a user is who they claim to be, usually with a username and password.

    • It sits at the edge of what is allowed, on both sides of each limit
    • Off by one errors appear there
    Model answer

    Boundary data sits at the edge of what is allowed, on both sides of each limit, such as 100 and 101. Off by one errors, like using < where <= was meant, appear at a boundary and nowhere else, so typical data would never reveal them.

    • count is local, so it is set to 0 again on each call
    • Pass the count in as a parameter and return the new value
    Model answer

    count is a local variable, created fresh and set to 0 on each call, so adding 1 always gives 1. To make it count, pass the current count in as a parameter and return the new value, for example count = tally(count), so the total is kept outside the function.

    • Meaningful identifiers, so readers know what each variable holds
    • Comments that explain why, constants or subprograms
    Model answer

    Meaningful identifiers, such as total_price instead of tp, tell the next reader what each variable holds without tracing the program. Comments that explain why a decision was made help someone change the code later without breaking it.

Round 3: Big Think

    • A while loop
    • A condition rejecting values below 0 or above 100
    • A type check, such as isdigit()
    • The entry is cast with int()
    • A helpful message for a rejected entry
    • Normal data, such as 55
    • Boundary data: 0 and 100, and -1 and 101
    • Erroneous data, such as cat or a blank
    Model answer
    Python
    mark = -1
    while mark < 0 or mark > 100:
        entry = input("Enter a mark between 0 and 100: ")
        if entry.isdigit():
            mark = int(entry)
        else:
            print("Please enter a whole number.")

    Normal data, such as 55, should be accepted. Boundary data, 0 and 100, should be accepted, while -1 and 101 should be rejected. Erroneous data, such as cat, a blank entry or 3.5, should be rejected with a message.

    • Split the program into functions and procedures
    • Code written once is reused, with no repetition
    • A change is made in one place
    • Each part can be tested on its own
    • Meaningful identifiers replace x and tmp
    • Comments explain why decisions were made
    • Constants hold fixed values
    • Local variables, parameters and clear indentation
    Model answer

    The team should split the program into functions and procedures, each with one job. Code written once can then be reused wherever it is needed, with no repetition, and a change is made in one place rather than in every copy. Each subprogram can be tested on its own before it is trusted, and local variables and parameters stop the parts interfering. Variables such as x and tmp should be renamed with meaningful identifiers, such as total_price, so the next reader knows what each holds. Comments should explain why decisions were made, fixed values should become constants such as VAT_RATE, and consistent indentation and blank lines make the structure visible.

This or That

  1. Procedure It does a job but returns nothing.
  2. Parameters Parameters are the names in the definition. Arguments are the values passed in.
  3. Runtime error The program started, then stopped while running.
  4. Logic error The program runs, but gives the wrong answer.
  5. Boundary It sits just outside the upper limit.
  6. Erroneous It should be rejected, because it is not a number at all.
  7. No: only that it is reasonable A sensible but wrong date passes every validation check.
  8. No: explain why instead Comments that restate the code earn nothing. Explain the decision.

Memory Match

  • A 6 Parameter: Name in a subprogram's definition
  • B 5 Argument: Value passed in when called
  • C 4 Local variable: Exists only while its subprogram runs
  • D 1 Syntax error: Breaks the language's rules, so it will not run
  • E 3 Logic error: Runs, but gives the wrong result
  • F 2 Runtime error: Stops the program while it is running

Sort It

  1. Runtime error Dividing by zero The program starts, then stops.
  2. Runtime error An index out of range It stops when the bad index is reached.
  3. Syntax error A missing quotation mark at the end of a string The program cannot even start.
  4. Logic error Using < where <= was meant An off by one logic error.
  5. Logic error Using + where - was meant It runs, but the answer is wrong.
  6. Syntax error A missing colon after if It breaks Python's rules, so the program will not run.
  7. Runtime error Opening a file that does not exist It stops when the open is attempted.
  8. Syntax error An unclosed bracket A syntax error, reported with a line number.
  9. Runtime error Calling int("cat") A ValueError stops the running program.
  10. Logic error Dividing a total by the wrong count The average comes out wrong, silently.
  11. Logic error A loop that adds the first item twice It runs, but the total is wrong.
  12. Syntax error Indentation that breaks a block Python reports indentation errors before running.