OCR J277 GCSE Computer Science · 2.2 Programming Fundamentals
Stretch tasks Additional Programming Techniques
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 python card to its result card.
- 12 cards: each python has a result
- 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 4 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: Additional Programming Techniques
Additional Programming Techniques: the questions
Quiz Challenge, round 1: Quiz Blitz
What does this print?
word = "Computing" print(word[0:3])What does this print?
print(len("Computing"))scores = [12, 45, 3, 78, 20]. What is scores[1]?
- 45
- 12
- 3
- 78
Which file mode adds to the end of a file without deleting what is there?
- "w"
- "r"
- "a"
Opening a file in "w" mode erases what was already in it.
- True
- False
Which SQL returns only the names of students in Year 11?
- SELECT * FROM Students WHERE Year = 11
- SELECT Name WHERE Year = 11 FROM Students
- SELECT Students FROM Name WHERE Year = 11
- SELECT Name FROM Students WHERE Year = 11
What is the difference between a parameter and an argument?
- An argument is a global variable
- A parameter is in the definition, an argument is the value passed in
- They are exactly the same
- A parameter is always a string
board is a 2D list. What does board[1][2] mean?
- Item number 12
- Rows 1 to 2
- Row 1, column 2
- Row 2, column 1
Which TWO are benefits of subroutines?
Tick 2.
- They remove the need for loops
- They stop the program needing input
- Code is written once and called many times
- Each one can be tested on its own
- They make every variable global
Why are local variables preferred to global ones?
- They can be used anywhere
- They never need a value
- Other parts of the program cannot change them by accident
- They are faster to type
What does random.randint(1, 6) give?
- A whole number from 1 to 6, including 6
- A whole number from 1 to 5
- A decimal between 1 and 6
- Always 1 or 6
In OCR's reference language, "Computing".substring(3,4) starts at index 3 and takes 4 characters. What does it give?
Quiz Challenge, round 2: Quick Fire
When finding the largest value in a list, explain why highest should start as the first item, not 0. [2 marks]
Explain the difference between a local and a global variable. [2 marks]
Write an SQL query to show the Name and Grade of every Year 11 student in the Students table. [3 marks]
A program must add a new score to scores.txt without losing the scores already saved. Which file mode should it use, and why? [2 marks]
Quiz Challenge, round 3: Big Think
Write a program that asks for five numbers, stores them in a list, then prints the total and the largest number. [4 marks]
Explain why programmers use subroutines. Use examples. [6 marks]
This or That: tick the right answer
What does this print?
print("Aisha"[0])- i
- A
Which SQL keyword chooses which rows to include?
- SELECT
- WHERE
In an SQL WHERE clause, does a number need quote marks?
- No: only text does
- Yes: every value does
What does SELECT * return?
- Every table
- Every column
Why close a file after using it?
- To delete its contents
- So the data is saved and the file freed
What does this print?
print("Hello"[::-1])- Hello
- olleH
A function differs from a procedure because it...
- Takes parameters
- Returns a value
What is the last index of a list of 10 items?
- 10
- 9
Memory Match: match each python to its result
| Python | Result |
|---|---|
A len("code") | 1 CODE |
B "code".upper() | 2 codecode |
C "code"[1:3] | 3 c |
D "code"[-1] | 4 od |
E "code" * 2 | 5 e |
F "code"[0] | 6 4 |
Sort It: tick one box in each row
String handling, arrays, file handling or SQL?
| Statement | Strings | Arrays | Files | SQL |
|---|---|---|---|---|
| A grid accessed by row, then column | ||||
name.upper() | ||||
| * means every column | ||||
| Fails if the file does not exist, in read mode | ||||
open("log.txt", "a") | ||||
scores.append(60) | ||||
file.close() | ||||
board[1][2] | ||||
WHERE Year = 11 | ||||
SELECT Name FROM Students | ||||
word[::-1] | ||||
first[0] + last |
Answers
Round 1: Quiz Blitz
- Com Python slicing stops before the end index, so [0:3] gives indexes 0, 1 and 2.
- 9 Computing has 9 characters.
- 45 Indexes start at 0, so scores[1] is the second item.
- "a" "a" is append. "w" erases the file first, and "r" only reads.
- True Use append mode to keep the existing data.
- SELECT Name FROM Students WHERE Year = 11 SELECT the columns, FROM the table, WHERE the rows match. * would give every column.
- A parameter is in the definition, an argument is the value passed in In def area(w, h), w and h are parameters. In area(5, 3), 5 and 3 are arguments.
- Row 1, column 2 Row first, then column.
- Code is written once and called many times; Each one can be tested on its own Subroutines also make code easier to maintain, reuse and read.
- Other parts of the program cannot change them by accident Their memory is also freed when the subroutine finishes.
- A whole number from 1 to 6, including 6 randint includes both ends, just like a dice.
- puti Index 3 is p, then u, t and i: puti.
Round 2: Quick Fire
- Every value in the list might be negative
- Then 0 would wrongly stay the highest, though it is not in the list
Model answerIf every value in the list were negative, 0 would never be replaced, so the answer would wrongly be 0, which is not even in the list.
- A local variable exists only inside the subroutine where it is created
- A global variable can be used anywhere in the program
Model answerA local variable exists only inside the subroutine where it is created. A global variable can be used anywhere in the program.
- SELECT Name, Grade
- FROM Students
- WHERE Year = 11
Model answerSELECT Name, Grade FROM Students WHERE Year = 11
- Append mode
- Write mode would erase the existing scores; append adds to the end
Model answerAppend mode, "a". Write mode would erase everything already in the file, but append adds the new score to the end.
Round 3: Big Think
- Adds each number to the list
- Repeats five times
- Casts each input to a number
- Works out the total
- Works out the largest
Model answerPythonnumbers = [] for i in range(5): numbers.append(int(input("Enter a number: "))) print("Total:", sum(numbers)) print("Largest:", max(numbers))- Written once and called many times, avoiding repetition
- Each can be tested on its own
- Easier to maintain: a bug is fixed in one place
- Can be reused in other programs
- Supports decomposition: each sub-problem becomes a subroutine
- Makes the program easier to read
- Uses parameters, so one subroutine works with different values
Model answerA subroutine is written once and can be called many times, which avoids repetition: a calculate_area(width, height) function can be used wherever an area is needed, with different arguments each time. Each subroutine can be tested on its own, and if there is a bug it is fixed in one place rather than in ten copies, which makes the program easier to maintain. Subroutines can be reused in other programs, and they support decomposition, because each sub-problem becomes a subroutine. A well-named call such as show_welcome(name) also makes the program easier to read.
This or That
- A Index 0 is the first character.
- WHERE SELECT picks the columns. WHERE picks the rows.
- No: only text does Write WHERE Year = 11, but WHERE Name = 'Aisha'.
- Every column The asterisk means all columns of the table named after FROM.
- So the data is saved and the file freed Closing makes sure everything is written and releases the file.
- olleH [::-1] steps backwards through the string, reversing it.
- Returns a value Both can take parameters. Only a function returns a value.
- 9 Indexes start at 0, so the last is the length minus 1.
Memory Match
- A 6
len("code"): 4 - B 1
"code".upper(): CODE - C 4
"code"[1:3]: od - D 5
"code"[-1]: e - E 2
"code" * 2: codecode - F 3
"code"[0]: c
Sort It
- Arrays A grid accessed by row, then column That is a 2D array.
- Strings
name.upper()Changing the case of text is string handling. - SQL * means every column SELECT * returns all the columns.
- Files Fails if the file does not exist, in read mode Read mode, "r", needs the file to be there.
- Files
open("log.txt", "a")Opening a file in append mode. - Arrays
scores.append(60)Adding an item to the end of a list. - Files
file.close()Closing a file saves it and releases it. - Arrays
board[1][2]Row then column in a 2D array. - SQL
WHERE Year = 11WHERE chooses which rows to include. - SQL
SELECT Name FROM StudentsA query that picks columns from a table. - Strings
word[::-1]Reversing a word is string handling. - Strings
first[0] + lastJoining text is concatenation, a string operation.