Pearson Edexcel 1CP2 GCSE Computer Science · Topic 6: Problem Solving with Programming
Stretch tasks Developing and Testing Programs
Quiz Challenge
A quiz game against four computer players, then short and long written answers.
- Quiz Blitz12 questions against the clock
- Quick Fire4 short answers
- Big Think2 long answers
About 20 minutes
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
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
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
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
In this code, what are 4 and 7?
def area(width, height): return width * height size = area(4, 7)- Arguments
- Parameters
- Constants
- Local variables
What does tally() return the third time it is called?
def tally(): count = 0 count = count + 1 return countWhich validation check is if 0 <= mark <= 100:?
- Range check
- Presence check
- Length check
- Format check
Which validation check is if "@" in email:?
- Format check
- Range check
- Type check
- Look up check
Validation checks that data is true.
- True
- False
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
A missing colon stops the program running at all. Which error is this?
- Syntax error
- Logic error
- Runtime error
- Validation error
A program runs but gives the wrong total. Which error is this?
- Authentication error
- Logic error
- Syntax error
- Runtime error
Dividing by zero stops a running program. Which kind of error is this?
For a mark from 0 to 100, which TWO are boundary test data?
Tick 2.
- cat
- 3.5
- 100
- 101
- 55
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
Explain the difference between validation and authentication. [2 marks]
Explain why boundary test data is important. [2 marks]
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 countGive two features of maintainable code and explain how each helps. [2 marks]
Quiz Challenge, round 3: Big Think
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]
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
def greet(name): print("Hello", name). Procedure or function?
- Procedure
- Function
In def area(width, height), what are width and height?
- Arguments
- Parameters
The program crashes because a file is missing. Which error?
- Syntax error
- Runtime error
Using + where - was meant: which error?
- Logic error
- Syntax error
For a mark from 0 to 100, which kind of test data is 101?
- Normal
- Boundary
"cat" entered as a mark is which kind of test data?
- Erroneous
- Boundary
Can validation prove a date of birth is true?
- No: only that it is reasonable
- Yes: that is its job
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
| Term | Meaning |
|---|---|
| A Parameter | 1 Breaks the language's rules, so it will not run |
| B Argument | 2 Stops the program while it is running |
| C Local variable | 3 Runs, but gives the wrong result |
| D Syntax error | 4 Exists only while its subprogram runs |
| E Logic error | 5 Value passed in when called |
| F Runtime error | 6 Name in a subprogram's definition |
Sort It: tick one box in each row
Syntax, logic or runtime? Sort each error.
| Statement | Syntax error | Logic error | Runtime 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
- A function returns a value Python uses def for both.
- Arguments Parameters are the names in the definition. Arguments are the values passed in.
- 1 count is local, so it starts at 0 on every call.
- Range check It tests that the value lies between limits.
- Format check It checks the entry matches a required pattern.
- False It checks that data is reasonable. A plausible but wrong date still passes.
- That users are who they claim to be Usually with a username and password.
- Syntax error It breaks the rules of Python, and is reported with a line number.
- Logic error Nothing reports a logic error, which is why they are expensive.
- runtime The program starts, then stops.
- 100; 101 Boundaries are tested on both sides: 0 and 100, and -1 and 101.
- 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 answerValidation 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 answerBoundary 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 answercount 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 answerMeaningful 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 answerPythonmark = -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 answerThe 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
- Procedure It does a job but returns nothing.
- Parameters Parameters are the names in the definition. Arguments are the values passed in.
- Runtime error The program started, then stopped while running.
- Logic error The program runs, but gives the wrong answer.
- Boundary It sits just outside the upper limit.
- Erroneous It should be rejected, because it is not a number at all.
- No: only that it is reasonable A sensible but wrong date passes every validation check.
- 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
- Runtime error Dividing by zero The program starts, then stops.
- Runtime error An index out of range It stops when the bad index is reached.
- Syntax error A missing quotation mark at the end of a string The program cannot even start.
- Logic error Using < where <= was meant An off by one logic error.
- Logic error Using + where - was meant It runs, but the answer is wrong.
- Syntax error A missing colon after if It breaks Python's rules, so the program will not run.
- Runtime error Opening a file that does not exist It stops when the open is attempted.
- Syntax error An unclosed bracket A syntax error, reported with a line number.
- Runtime error Calling int("cat") A ValueError stops the running program.
- Logic error Dividing a total by the wrong count The average comes out wrong, silently.
- Logic error A loop that adds the first item twice It runs, but the total is wrong.
- Syntax error Indentation that breaks a block Python reports indentation errors before running.