Edexcel GCSE CS · 6.1
Developing and Testing Programs
Name
Class
Date
Mark / 25
Section A
Circle the letter of the correct answer. One mark each.
- 1What is the difference between a procedure and a function?1
- AA function is always longer
- BA procedure cannot take parameters
- CA function returns a value and a procedure does not
- DA procedure runs faster
- 2In def area(width, height), what are width and height?1
- AReturn values
- BParameters
- CArguments
- DGlobal variables
- 3A program will not run and Python reports a missing colon. What kind of error is this?1
- ARuntime error
- BSyntax error
- CValidation error
- DLogic error
- 4A program runs but calculates an average by dividing by the wrong number. What kind of error is this?1
- ARuntime error
- BType error
- CSyntax error
- DLogic error
- 5For a value that must be between 1 and 20, which set is boundary test data?1
- A0, 1, 20, 21
- B10, 11, 12
- C1, 2, 3
- Dcat, blank, 2.5
- 6What can validation never do?1
- ACheck the data type
- BCheck a value is within a range
- CCheck a field is not empty
- DConfirm that the data entered is truthful
- 7Why does a subprogram that initialises its counter internally return the same value every call?1
- APython does not support counters
- BThe return statement is misplaced
- CThe parameter is missing
- DThe counter is local and is created fresh on each call
- 8Which is the best example of a useful comment?1
- A# add one to count
- B# this is a loop
- C# skip the first line because it holds the column headings
- D# variable
- 9A program stops with an error when it tries to open a file that has been deleted. What kind of error is this?1
- ARuntime error
- BDesign error
- CLogic error
- DSyntax error
- 10What is erroneous test data used to check?1
- AThat the boundaries are right
- BThat the program is fast enough
- CThat the program correctly rejects data it should not accept
- DThat typical values are handled
Section B
Answer in the space provided. The number of marks tells you how many separate points to make.
- 1StateState one advantage of using subprograms in a long program.2
- 2WriteWrite a Python validation loop that repeatedly asks the user for a whole number between 1 and 10 until a valid value is entered.4
- 3ExplainExplain the difference between validation and authentication.3
- 4DescribeDescribe the three types of error a programmer may encounter, giving an example of each.6
Mark scheme
Section A
Section B
1 State one advantage of using subprograms in a long program. 2
One mark for each of the following, to a maximum of 2.
- Code written once can be called from many places, reducing repetition
- Or each subprogram can be tested and maintained on its own
Model answer. A task written once as a subprogram can be called from every point that needs it, which removes repeated code, and because that task lives in one named place a correction only has to be made once rather than in every copy.
2 Write a Python validation loop that repeatedly asks the user for a whole number between 1 and 10 until a valid value is entered. 4
One mark for each of the following, to a maximum of 4.
- Uses a while loop that repeats until the value is acceptable
- Checks that the entry is a whole number
- Checks that the value is within the range 1 to 10
- Gives the user a message when the entry is rejected
Model answer. A correct answer is: number = 0, then while number < 1 or number > 10:, then entry = input("Enter a number from 1 to 10: "), then if entry.isdigit(): number = int(entry), then if number < 1 or number > 10: print("That is outside the range."), else: print("Please enter a whole number."). The loop condition must be false only for acceptable values, the entry must be checked for being numeric before int() is applied so that typing a word does not crash the program, and a message tells the user what was wrong rather than simply asking again.
3 Explain the difference between validation and authentication. 3
One mark for each of the following, to a maximum of 3.
- Validation checks that data entered is reasonable or of the expected form
- Authentication checks that a user is who they claim to be
- Gives an example of each, such as a range check and a password
Model answer. Validation is a check on the data itself, confirming that what has been entered is reasonable and of the form expected, for example that a mark lies between 0 and 100 or that a required field is not blank. It says nothing at all about who typed it. Authentication is a check on the person, confirming that the user is who they claim to be, usually through a username and password or a biometric check. The two are separate jobs: a system with perfect validation still has no idea who is using it, and a system with strong authentication will still accept a nonsensical value if it does not validate.
4 Describe the three types of error a programmer may encounter, giving an example of each. 6
One mark for each of the following, to a maximum of 6.
- A syntax error breaks the rules of the language
- Gives an example such as a missing colon or bracket, and notes the program will not run
- A logic error means the program runs but gives the wrong result
- Gives an example such as using the wrong operator, and notes nothing reports it
- A runtime error occurs while the program is executing and stops it
- Gives an example such as dividing by zero or an index out of range
Model answer. A syntax error breaks the rules of the programming language, for example a missing colon at the end of an if statement or an unclosed bracket. Python cannot interpret the line, so the program does not run at all and the error is reported with a line number, which makes it the easiest kind to fix. A logic error is different in kind: the code is valid, so the program runs from start to finish, but the instructions do not do what the programmer intended, so the output is wrong. Using a plus where a minus was meant, or less than where less than or equal to was meant, produces a logic error, and nothing reports it, which means it can only be found by testing with data whose correct answer is already known or by tracing the program by hand. A runtime error occurs while the program is executing and causes it to stop, for example dividing by zero, reading past the end of a list, or trying to open a file that does not exist. The program was valid and started normally, so a runtime error usually reflects data the programmer did not anticipate rather than a mistake in the code's structure, which is why validation and error handling reduce them.