OCR J277 GCSE Computer Science · 2.2 Programming Fundamentals

Stretch tasks Programming Fundamentals

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 expression card to its value card.

  • 12 cards: each expression has a value
  • 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: Programming Fundamentals

Programming Fundamentals: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. What is a constant?

    • A variable that is used often
    • A value typed in by the user
    • A loop that never ends
    • A named value that cannot change while the program runs
  2. What does this print?

    print(17 % 5)

  3. What does this print?

    print(17 // 5)

  4. Which construct chooses between different paths?

    • Iteration
    • Casting
    • Selection
    • Sequence
  5. range(5) gives the numbers 1 to 5.

    • True
    • False
  6. What does this print?

    mark = 80
    if mark >= 50:
        print("Pass")
    elif mark >= 70:
        print("Distinction")
    else:
        print("Fail")
    • Fail
    • Pass, then Distinction
    • Pass
    • Distinction
  7. Which kind of loop repeats until a condition changes?

    • A count-controlled loop
    • A for loop over range(10)
    • A loop with no condition
    • A condition-controlled loop
  8. How many times does print run?

    for row in range(3):
        for col in range(4):
            print("*")

  9. Which TWO are reasons to use a constant?

    Tick 2.

    • Changing the value means editing one line
    • It cannot be changed by accident
    • It makes the program run faster
    • It can hold any data type at once
    • It lets the user change the value
  10. What does x == 5 do?

    • Checks whether x is 5
    • Puts 5 into x
    • Adds 5 to x
    • Makes x a constant
  11. The condition age >= 13 and age <= 19 is True when age is 15.

    • True
    • False
  12. Which test checks whether a number is even?

    • number % 2 == 1
    • number % 2 == 0
    • number // 2 == 0
    • number / 2 == 1

Quiz Challenge, round 2: Quick Fire

  1. Explain the difference between a variable and a constant. [2 marks]

  2. Name the three basic programming constructs. [3 marks]

  3. Explain why the order of these conditions is wrong, and how to fix it. [2 marks]

    if mark >= 50:
        print("Pass")
    elif mark >= 70:
        print("Distinction")

  4. Explain what MOD and DIV do, using 17 and 5 as an example. [2 marks]

Quiz Challenge, round 3: Big Think

  1. Write an algorithm that keeps asking for a password until the user enters opensesame, then displays Access granted. [4 marks]

  2. Explain how sequence, selection and iteration are used in a program that asks for five test marks and shows how many of them are passes. [6 marks]

This or That: tick the right answer

  1. Which operator gives the remainder after division?

    • DIV
    • MOD
  2. What does range(1, 6) give?

    • 1 to 5
    • 1 to 6
  3. Which is the better variable name?

    • totalPrice
    • t
  4. What does this print?

    print(2 ** 3)
    • 6
    • 8
  5. In a nested loop, how often does the inner loop run?

    • Fully, for every turn of the outer loop
    • Once, after the outer loop ends
  6. Which operator is True only when both conditions are True?

    • OR
    • AND
  7. A while loop's condition can never become false. What happens?

    • It runs once
    • It loops forever
  8. Which comes first in a well-ordered if, elif chain?

    • The most restrictive test
    • The least restrictive test

Memory Match: match each expression to its value

ExpressionValue
A 17 % 51 3
B 17 // 52 3.4
C 17 / 53 16
D 2 ** 44 2
E 7 + 3 * 25 5
F len("hello")6 13

Sort It: tick one box in each row

Sequence, selection or iteration?

StatementSequenceSelectionIteration
if mark >= 50:
elif and else branches
A switch statement with several cases
A count-controlled loop
Repeating until the user types quit
Lines run in the order they are written
Choosing between two paths based on a condition
Instructions carried out one after another
Setting total to 0 before adding to it
Asking for a name, then printing a greeting
while password != secret:
for i in range(10):
Answers

Round 1: Quiz Blitz

  1. A named value that cannot change while the program runs Constants such as VAT_RATE are set once and never change.
  2. 2 % is MOD: 17 divided by 5 is 3 remainder 2.
  3. 3 // is DIV, integer division: 5 goes into 17 three whole times.
  4. Selection Selection uses if, elif and else to pick a path based on a condition.
  5. False range(5) gives 0, 1, 2, 3 and 4. range(1, 6) gives 1 to 5.
  6. Pass 80 >= 50 is true, so the first branch runs and the rest are skipped. Put the most restrictive test first.
  7. A condition-controlled loop A while loop is condition-controlled. A for loop is count-controlled.
  8. 12 The inner loop runs 4 times for each of the 3 outer turns: 3 x 4 = 12.
  9. Changing the value means editing one line; It cannot be changed by accident A constant also gives a meaningful name to a value, such as VAT_RATE instead of 0.2.
  10. Checks whether x is 5 One equals sign assigns. Two compare.
  11. True 15 is at least 13 and at most 19, so both parts are true, and AND needs both.
  12. number % 2 == 0 An even number leaves no remainder when divided by 2.

Round 2: Quick Fire

    • A variable's value can change while the program runs
    • A constant's value is fixed once it is set
    Model answer

    A variable is a named location whose value can change while the program runs. A constant is a named value that is fixed once it has been set.

    • Sequence
    • Selection
    • Iteration
    Model answer

    Sequence, selection and iteration.

    • A mark of 70 or more also passes the first test
    • So Distinction is never reached: check mark >= 70 first
    Model answer

    Any mark of 70 or more is also true for the first test, mark >= 50, so it prints Pass and the Distinction branch is never reached. The conditions should be swapped, so mark >= 70 is checked first.

    • MOD gives the remainder: 17 MOD 5 is 2
    • DIV is integer division: 17 DIV 5 is 3
    Model answer

    MOD gives the remainder after division, so 17 MOD 5 is 2. DIV gives the whole number part of a division, so 17 DIV 5 is 3.

Round 3: Big Think

    • Uses a loop
    • Asks for the password inside the loop
    • Compares the entry with the correct password
    • Shows the message after the loop
    • Sets the password to an empty string before the loop
    Model answer

    The while loop keeps asking until the password matches, then the message is shown after the loop:

    Python
    password = ""
    while password != "opensesame":
        password = input("Enter the password: ")
    print("Access granted")
    • Sequence: steps run in order, such as setting the count before the loop
    • Selection: if a mark is 50 or more, it counts as a pass
    • Iteration: a loop repeats five times
    • Each mark is input inside the loop
    • A counter goes up by 1 for each pass
    • The result is output after the loop
    • The input is cast to an integer
    Model answer

    Sequence: the steps run in order, so passes is set to 0 before the loop and the result is shown after the loop. Iteration: the for loop uses range to repeat five times, asking for a mark each time, and the input is cast to an integer. Selection: if the mark is 50 or more, the count of passes goes up by 1.

    Python
    passes = 0
    for i in range(5):
        mark = int(input("Enter a mark: "))
        if mark >= 50:
            passes = passes + 1
    print("Passes:", passes)

This or That

  1. MOD MOD, or % in Python, gives the remainder. DIV gives the whole number part.
  2. 1 to 5 range stops one before its end value.
  3. totalPrice Meaningful names make code easier to read, and examiners notice.
  4. 8 ** is the exponent: 2 to the power 3 is 8.
  5. Fully, for every turn of the outer loop The inner loop completes entirely for each single turn of the outer loop.
  6. AND OR needs only one of them to be True.
  7. It loops forever That is an infinite loop: something inside must change the condition.
  8. The most restrictive test Test mark >= 70 before mark >= 50, or high marks never reach their branch.

Memory Match

  • A 4 17 % 5: 2
  • B 1 17 // 5: 3
  • C 2 17 / 5: 3.4
  • D 3 2 ** 4: 16
  • E 6 7 + 3 * 2: 13
  • F 5 len("hello"): 5

Sort It

  1. Selection if mark >= 50: An if statement chooses a path: selection.
  2. Selection elif and else branches Extra branches are still selection.
  3. Selection A switch statement with several cases Choosing one case out of many is selection.
  4. Iteration A count-controlled loop Count-controlled loops are one of the two kinds of iteration.
  5. Iteration Repeating until the user types quit Repeating is iteration.
  6. Sequence Lines run in the order they are written Sequence is the default way code runs.
  7. Selection Choosing between two paths based on a condition That is the definition of selection.
  8. Sequence Instructions carried out one after another That is the definition of sequence.
  9. Sequence Setting total to 0 before adding to it Getting the order right is part of sequence.
  10. Sequence Asking for a name, then printing a greeting Two steps in order: sequence.
  11. Iteration while password != secret: A while loop repeats until its condition is false.
  12. Iteration for i in range(10): A for loop repeats: iteration.