OCR J277 GCSE Computer Science · 2.2 Programming Fundamentals
Stretch tasks Programming Fundamentals
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 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
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
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
What does this print?
print(17 % 5)What does this print?
print(17 // 5)Which construct chooses between different paths?
- Iteration
- Casting
- Selection
- Sequence
range(5) gives the numbers 1 to 5.
- True
- False
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
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
How many times does print run?
for row in range(3): for col in range(4): print("*")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
What does x == 5 do?
- Checks whether x is 5
- Puts 5 into x
- Adds 5 to x
- Makes x a constant
The condition age >= 13 and age <= 19 is True when age is 15.
- True
- False
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
Explain the difference between a variable and a constant. [2 marks]
Name the three basic programming constructs. [3 marks]
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")Explain what MOD and DIV do, using 17 and 5 as an example. [2 marks]
Quiz Challenge, round 3: Big Think
Write an algorithm that keeps asking for a password until the user enters opensesame, then displays Access granted. [4 marks]
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
Which operator gives the remainder after division?
- DIV
- MOD
What does range(1, 6) give?
- 1 to 5
- 1 to 6
Which is the better variable name?
- totalPrice
- t
What does this print?
print(2 ** 3)- 6
- 8
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
Which operator is True only when both conditions are True?
- OR
- AND
A while loop's condition can never become false. What happens?
- It runs once
- It loops forever
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
| Expression | Value |
|---|---|
A 17 % 5 | 1 3 |
B 17 // 5 | 2 3.4 |
C 17 / 5 | 3 16 |
D 2 ** 4 | 4 2 |
E 7 + 3 * 2 | 5 5 |
F len("hello") | 6 13 |
Sort It: tick one box in each row
Sequence, selection or iteration?
| Statement | Sequence | Selection | Iteration |
|---|---|---|---|
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
- A named value that cannot change while the program runs Constants such as VAT_RATE are set once and never change.
- 2 % is MOD: 17 divided by 5 is 3 remainder 2.
- 3 // is DIV, integer division: 5 goes into 17 three whole times.
- Selection Selection uses if, elif and else to pick a path based on a condition.
- False range(5) gives 0, 1, 2, 3 and 4. range(1, 6) gives 1 to 5.
- Pass 80 >= 50 is true, so the first branch runs and the rest are skipped. Put the most restrictive test first.
- A condition-controlled loop A while loop is condition-controlled. A for loop is count-controlled.
- 12 The inner loop runs 4 times for each of the 3 outer turns: 3 x 4 = 12.
- 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.
- Checks whether x is 5 One equals sign assigns. Two compare.
- True 15 is at least 13 and at most 19, so both parts are true, and AND needs both.
- 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 answerA 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 answerSequence, selection and iteration.
- A mark of 70 or more also passes the first test
- So Distinction is never reached: check mark >= 70 first
Model answerAny 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 answerMOD 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 answerThe while loop keeps asking until the password matches, then the message is shown after the loop:
Pythonpassword = "" 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 answerSequence: 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.
Pythonpasses = 0 for i in range(5): mark = int(input("Enter a mark: ")) if mark >= 50: passes = passes + 1 print("Passes:", passes)
This or That
- MOD MOD, or % in Python, gives the remainder. DIV gives the whole number part.
- 1 to 5 range stops one before its end value.
- totalPrice Meaningful names make code easier to read, and examiners notice.
- 8 ** is the exponent: 2 to the power 3 is 8.
- Fully, for every turn of the outer loop The inner loop completes entirely for each single turn of the outer loop.
- AND OR needs only one of them to be True.
- It loops forever That is an infinite loop: something inside must change the condition.
- 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
- Selection
if mark >= 50:An if statement chooses a path: selection. - Selection
elifandelsebranches Extra branches are still selection. - Selection A switch statement with several cases Choosing one case out of many is selection.
- Iteration A count-controlled loop Count-controlled loops are one of the two kinds of iteration.
- Iteration Repeating until the user types quit Repeating is iteration.
- Sequence Lines run in the order they are written Sequence is the default way code runs.
- Selection Choosing between two paths based on a condition That is the definition of selection.
- Sequence Instructions carried out one after another That is the definition of sequence.
- Sequence Setting total to 0 before adding to it Getting the order right is part of sequence.
- Sequence Asking for a name, then printing a greeting Two steps in order: sequence.
- Iteration
while password != secret:A while loop repeats until its condition is false. - Iteration
for i in range(10):A for loop repeats: iteration.