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.

GCSE Computer Science · 2.2.1

Programming Fundamentals

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 20 marks. Total 30 marks.

Name

Class

Date

Mark  / 30

Section A

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

  1. 1What is the difference between a variable and a constant?1
    1. AA variable's value can change during execution, a constant's cannot
    2. BThere is no difference
    3. CA constant can change but a variable cannot
    4. DVariables are stored in ROM and constants in RAM
  2. 2What does 17 MOD 5 evaluate to?1
    1. A2
    2. B3
    3. C3.4
    4. D85
  3. 3How many times does for i in range(3) execute the loop body?1
    1. A0
    2. B2
    3. C3
    4. D4
  4. 4Which loop should be used when the number of repetitions is not known in advance?1
    1. AA count controlled loop such as for
    2. BNo loop, use selection instead
    3. CA nested for loop
    4. DA condition controlled loop such as while
  5. 5What does 17 DIV 5 evaluate to?1
    1. A2
    2. B3
    3. C3.4
    4. D12
  6. 6Which condition correctly tests whether a number stored in n is even?1
    1. An % 2 == 0
    2. Bn == 2
    3. Cn / 2 == 0
    4. Dn % 2 == 1
  7. 7What is wrong with if score = 100: in Python?1
    1. AScore cannot be compared with a number
    2. BNothing is wrong
    3. CThe colon should be a semicolon
    4. DA single equals sign assigns a value, a comparison needs two
  8. 8In a nested loop where the outer runs 4 times and the inner runs 5 times, how many times does the inner body execute in total?1
    1. A4
    2. B5
    3. C9
    4. D20
  9. 9Which expression is true when age is 15?1
    1. Aage == 13 or age == 19
    2. Bage >= 13 and age <= 19
    3. Cnot (age > 10)
    4. Dage > 15 and age < 13
  10. 10Why should a program use a constant for a VAT rate rather than typing 0.2 throughout?1
    1. AConstants make the program run faster
    2. BThe compiler requires it
    3. CIf the rate changes, only one line needs editing and the name explains the value
    4. DConstants use less memory than variables

Section B

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

  1. 1StateState the difference between a variable and a constant, and give one reason a programmer would use a constant.3
  2. 2ExplainExplain the difference between a count controlled loop and a condition controlled loop, giving an example use for each.4
  3. 3WriteWrite a program that asks the user to enter numbers repeatedly until they enter 0, then outputs how many numbers were entered and their total.6
  4. 4ExplainA program contains the following selection statement, which is intended to award grades. Explain why a mark of 85 would be given the wrong grade. if mark >= 40 then print("Pass") elseif mark >= 70 then print("Distinction") endif3
  5. 5ExplainExplain what the MOD operator does and give two situations where it would be useful in a program.4

Mark scheme

Section A

1A2A3C4D5B6A7D8D9B10C

Section B

1 State the difference between a variable and a constant, and give one reason a programmer would use a constant. 3

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

  • A variable can change value while the program runs
  • A constant cannot be changed once set
  • Reason such as preventing accidental change, or only needing to edit one line if the value changes

Model answer. A variable is a named memory location whose value can be changed at any point while the program is running, whereas a constant is given a value once and that value cannot be changed afterwards. A programmer would use a constant for a value such as a VAT rate or the maximum number of players, because it prevents the value being altered accidentally elsewhere in the program, and if the value ever does need updating it appears in only one place, so only one line has to be edited.

2 Explain the difference between a count controlled loop and a condition controlled loop, giving an example use for each. 4

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

  • A count controlled loop repeats a known fixed number of times
  • Example such as processing every item in an array of known length
  • A condition controlled loop repeats until a condition is met, and the number of repetitions is not known in advance
  • Example such as repeatedly asking for input until it is valid

Model answer. A count controlled loop repeats a known, fixed number of times, which is decided before the loop begins. It would be used, for example, to work through every element of an array of 20 marks, because the number of iterations required is known to be 20. A condition controlled loop repeats for as long as, or until, a particular condition holds, and the number of repetitions is not known when the loop starts. It would be used, for example, to keep asking the user to enter a password until they type the correct one, since there is no way to know in advance how many attempts they will need.

3 Write a program that asks the user to enter numbers repeatedly until they enter 0, then outputs how many numbers were entered and their total. 6

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

  • Initialises a counter and a total to zero
  • Uses a condition controlled loop
  • Takes input inside the loop and converts it to a number
  • Stops the loop when 0 is entered
  • Adds each valid number to the total and increments the counter
  • Outputs both the count and the total after the loop

Model answer. count = 0 total = 0 number = int(input("Enter a number, or 0 to finish: ")) while number != 0: total = total + number count = count + 1 number = int(input("Enter a number, or 0 to finish: ")) print("You entered", count, "numbers") print("Their total is", total) The counter and total are initialised to zero before the loop. The first number is read before the loop so that the condition can be tested. The while loop continues for as long as the number entered is not 0, adding each value to the running total, increasing the counter and then reading the next number. When 0 is entered the loop ends without counting the 0 itself, and the count and total are output.

4 A program contains the following selection statement, which is intended to award grades. Explain why a mark of 85 would be given the wrong grade. if mark >= 40 then print("Pass") elseif mark >= 70 then print("Distinction") endif 3

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

  • The conditions are tested in order from the top
  • 85 satisfies the first condition mark >= 40, so Pass is printed
  • The elseif is never reached, so the fix is to test the most restrictive condition first

Model answer. Selection statements are evaluated from the top downwards, and as soon as one condition is found to be true its block runs and the remaining branches are skipped entirely. A mark of 85 satisfies the first condition, because 85 is greater than or equal to 40, so the program prints Pass and the elseif testing for 70 or above is never reached. The fix is to reorder the conditions so that the most restrictive is tested first: check whether the mark is at least 70 and award Distinction, and only then check whether it is at least 40 and award Pass.

5 Explain what the MOD operator does and give two situations where it would be useful in a program. 4

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

  • MOD returns the remainder after a division
  • Gives a correct example of its value, such as 17 MOD 5 being 2
  • First use such as testing whether a number is even or odd
  • Second use such as extracting units of time, or cycling through a fixed set of values

Model answer. The MOD operator carries out a division and returns the remainder rather than the quotient, so 17 MOD 5 gives 2 because 5 goes into 17 three times with 2 left over. One useful application is testing whether a number is even or odd: if a number MOD 2 equals 0 then it divides exactly by two and is therefore even, which is a very common requirement in filtering and alternating logic. A second application is breaking a value into units, for example converting a total number of seconds into minutes and seconds, where the total DIV 60 gives the number of whole minutes and the total MOD 60 gives the seconds left over. MOD is also used to cycle a value within a fixed range, such as wrapping a player position around the edge of a game board.