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 1

Exam Pseudocode to Python

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 15 marks. Total 25 marks.

Name

Class

Date

Mark  / 25

Section A

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

  1. 1Which Python expression is the same as 17 MOD 5 in exam pseudocode?1
    1. A17 // 5
    2. B17 ** 5
    3. C17 / 5
    4. D17 % 5
  2. 2What is the value of 17 // 5 in Python?1
    1. A2
    2. B3
    3. C3.4
    4. D4
  3. 3Which line is the Python for the exam loop for i = 1 to 5?1
    1. Afor i in range(1, 5):
    2. Bfor i in range(5):
    3. Cfor i in range(1, 6):
    4. Dfor i in range(0, 5):
  4. 4What does 2 ^ 3 evaluate to in Python?1
    1. A1
    2. B5
    3. C6
    4. D8
  5. 5Which structure replaces an exam do ... until x > 10 loop in Python?1
    1. Awhile x > 10: and nothing else
    2. Bwhile True: with if x > 10: break at the bottom
    3. Cif x > 10: placed before the loop
    4. Dfor x in range(10):
  6. 6Which function turns the character "A" into its ASCII code 65?1
    1. Achr
    2. Bstr
    3. Cint
    4. Dord
  7. 7What is bool("False") in Python?1
    1. ATrue
    2. BNone
    3. CAn error
    4. DFalse
  8. 8If word = "Computing", what is word[2:5]?1
    1. A"omp"
    2. B"put"
    3. C"mput"
    4. D"mpu"
  9. 9How does Python store a single character such as "A"?1
    1. AAs a string of length one
    2. BAs a Boolean
    3. CAs an integer
    4. DAs a char
  10. 10What are the values of 7 // 2 and 7 / 2?1
    1. A3 and 3
    2. B4 and 3.5
    3. C3 and 3.5
    4. D3.5 and 3

Section B

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

  1. 1StateA program contains the lines minutes = total_seconds DIV 60 and seconds = total_seconds MOD 60. State the value of minutes and the value of seconds when total_seconds is 185.2
  2. 2WriteWrite the Python equivalent of the following OCR reference language.3
    OCR reference language
    total = 0
    for i = 1 to 10
        total = total + i * i
    next i
    print(total)
  3. 3ExplainA student writes age = input("Age: ") followed by if age >= 18:. Explain why this raises an error and show how to correct it.4
  4. 4DescribeA Caesar cipher shifts every letter along the alphabet and wraps round after Z. Describe how the MOD operator is used to make the shifted letter wrap round.3
  5. 5ConvertConvert the following loop into Python. The loop must behave exactly as the original does.3
    OCR reference language
    do
        guess = int(input("Guess: "))
    until guess == 7

Mark scheme

Section A

1D2B3C4A5B6D7A8D9A10C

Section B

1 A program contains the lines minutes = total_seconds DIV 60 and seconds = total_seconds MOD 60. State the value of minutes and the value of seconds when total_seconds is 185. 2

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

  • minutes is 3
  • seconds is 5

Model answer. 185 DIV 60 is 3, because 60 goes into 185 three times. 185 MOD 60 is 5, because three lots of 60 make 180 and the remainder is 5. So minutes is 3 and seconds is 5.

2 Write the Python equivalent of the following OCR reference language. 3

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

  • Uses range(1, 11) so that 10 is included
  • Adds i * i to the total inside the loop
  • Prints the total after the loop, not inside it

Model answer.

The Python loop must run to 10 inclusive, so the stop value is 11.

Python
total = 0
for i in range(1, 11):
    total = total + i * i
print(total)

The print is not indented, so it happens once after the loop has finished. The program prints 385.

3 A student writes age = input("Age: ") followed by if age >= 18:. Explain why this raises an error and show how to correct it. 4

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

  • input always returns a string
  • A string cannot be compared with an integer using >=
  • The value must be cast to an integer
  • Corrected code is age = int(input("Age: "))

Model answer.

The input function always returns a string, even when the user types digits. Python cannot compare a string with the integer 18 using >=, so it raises a TypeError. The string has to be converted to an integer first, by casting it.

Python
age = int(input("Age: "))
if age >= 18:
    print("Adult")

4 A Caesar cipher shifts every letter along the alphabet and wraps round after Z. Describe how the MOD operator is used to make the shifted letter wrap round. 3

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

  • Each letter is converted to a position from 0 to 25
  • The shift is added and the total is MOD 26
  • The remainder is always between 0 and 25 so Y plus 3 wraps to B

Model answer. Each letter is first turned into its position in the alphabet, from 0 for A to 25 for Z. The shift is added, then the total is taken MOD 26. The remainder after dividing by 26 can only be between 0 and 25, so a total that goes past 25 comes back round to the start of the alphabet. For example Y is position 24, 24 plus 3 is 27, and 27 MOD 26 is 1, which is B.

5 Convert the following loop into Python. The loop must behave exactly as the original does. 3

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

  • Uses a loop that cannot end by itself such as while True
  • Reads the guess inside the loop and casts it to an integer
  • Uses an if with break when the guess equals 7

Model answer.

The body must run once before the test, so the loop is a while True with the exit condition checked at the bottom.

Python
while True:
    guess = int(input("Guess: "))
    if guess == 7:
        break