2.2.3 Additional programming techniques Practice Questions
GCSE · Paper 2 · Computational thinking, algorithms and programming · 12 practice questions · 47 marks
Exam questions for 2.2.3 Additional programming techniques
12 practice questions (47 marks) with mark schemes
Answer each question, reveal the mark scheme, then award yourself marks. Scores and answers are saved in this browser so you can see which topics need more work.
Practice questions
- Question 1Practice question · J277/02 style4 marks
A program contains this code.
01 word = "cinnamon" 02 print(word.length) 03 print(word.left(3)) 04 print(word.right(4)) 05 print(word.substring(2, 3))State the four values that are printed, in order.
Show mark scheme
Line 02: 8 (1) Line 03: cin (1) Line 04: amon (1) Line 05: nna (1) Method: the letters are c0 i1 n2 n3 a4 m5 o6 n7. Right 4 is positions 4 to 7. Substring(2, 3) starts at position 2 and takes 3 characters: n, n, a.
Mark yourself: how many marks did you get?/ 4 - Question 2Practice question · J277/02 style2 marks
The variable age holds the integer 15 and the variable first holds "Ravi".
01 print("Hello " + first + ", you are " + str(age))(a) State what is printed. [1] (b) Explain why str(age) is used. [1]
Show mark scheme
(a) Hello Ravi, you are 15 (1) (b) age is an integer and + can only join strings together / the integer must be cast to a string before it can be concatenated (1)
Mark yourself: how many marks did you get?/ 2 - Question 3Practice question · J277/02 style4 marks
The file "scores.txt" holds four lines: 12, 18, 9 and 21.
01 total = 0 02 scoreFile = open("scores.txt") 03 while NOT scoreFile.endOfFile() 04 total = total + int(scoreFile.readLine()) 05 endwhile 06 scoreFile.close() 07 print(total)(a) State the value that is printed. [2] (b) Explain why int() is used on line 04. [1] (c) Give one reason why line 06 is needed. [1]
Show mark scheme
(a) 60 (2). Method: total goes 12, then 30, then 39, then 60. Award 1 mark for correct working if the final answer is wrong. (b) readLine() returns a string / a string cannot be added to a number (1) (c) To make sure the data is saved and the file is released / so other programs can use the file / so the file is not damaged (1)
Mark yourself: how many marks did you get?/ 4 - Question 4Practice question · J277/02 style5 marks
A table called Games stores computer games.
Title Genre Rating Price Skyline Racing 12 20 Dark Vale Horror 16 35 Pixel Farm Puzzle 3 10 Night Rally Racing 7 25 Crypt Run Horror 12 15 (a) Write an SQL statement to show the Title of every Racing game. [2] (b) State the result of this statement. [1]
SELECT Title FROM Games WHERE Genre = "Horror" AND Rating = 12(c) State the result of this statement. [2]
SELECT Title, Price FROM Games WHERE Price > 20 OR Rating = 3Show mark scheme
(a) SELECT Title FROM Games (1) WHERE Genre = "Racing" (1) (b) Crypt Run (1). Dark Vale is Horror but its rating is 16. (c) Title and Price shown for each row (1); the three rows Dark Vale 35, Pixel Farm 10 and Night Rally 25 (1). Skyline has a price of exactly 20 so it is not included. Crypt Run fails both conditions.
Mark yourself: how many marks did you get?/ 5 - Question 5Practice question · J277/02 style2 marks
A table called Pets stores animals at a rescue centre.
Name Type Age Biscuit Dog 3 Pip Rabbit 1 Misty Cat 6 Rex Dog 9 (a) State how many records are in the table. [1] (b) State how many fields are in the table. [1]
Show mark scheme
(a) 4 (1) (b) 3 (1)
Mark yourself: how many marks did you get?/ 2 - Question 6Practice question · J277/02 style3 marks
01 array temps = [14, 9, 21, 17, 6] 02 highest = temps[0] 03 for i = 1 to 4 04 if temps[i] > highest then 05 highest = temps[i] 06 endif 07 next i 08 print(highest)(a) State the value that is printed. [1] (b) Describe what the program does. [1] (c) State the index of the value 6 in the array. [1]
Show mark scheme
(a) 21 (1). Method: highest starts at 14. 9 is not bigger. 21 is bigger so highest becomes 21. 17 and 6 are not bigger. (b) It finds and prints the largest value in the array (1) (c) 4 (1)
Mark yourself: how many marks did you get?/ 3 - Question 7Practice question · J277/02 style5 marks
A cafe stores its menu in a 2D array. Each row is one item and holds its name and its price.
01 array menu[3,2] 02 menu[0,0] = "Soup" 03 menu[0,1] = "4" 04 menu[1,0] = "Pizza" 05 menu[1,1] = "9" 06 menu[2,0] = "Salad" 07 menu[2,1] = "6" 08 print(menu[1,0] + " costs " + menu[1,1])(a) State what is printed by line 08. [1] (b) State what is printed by print(menu[2,0]). [1] (c) Write one line of code to change the price of the soup to "5". [1] (d) Explain what each row and each column of the array represents. [2]
Show mark scheme
(a) Pizza costs 9 (1) (b) Salad (1) (c) menu[0,1] = "5" (1) (d) Each row is one record / one menu item (1). Each column is one field / one piece of data about the item, such as the name or the price (1).
Mark yourself: how many marks did you get?/ 5 - Question 8Practice question · J277/02 style5 marks
Tickets for a show cost 8 pounds each. If a customer buys 5 or more tickets they get 10% off the total cost. Write a function called ticketCost that takes the number of tickets as a parameter and returns the total cost. Write your answer in the OCR Exam Reference Language or a high-level programming language.
Show mark scheme
function ticketCost(tickets) // (1) total = tickets * 8 // (1) if tickets >= 5 then // (1) total = total * 0.9 // (1) endif return total // (1) endfunctionCheck: ticketCost(3) gives 24. ticketCost(5) gives 40 * 0.9 = 36. Accept total * 0.1 subtracted from total. Accept a high-level language equivalent. Allow the 5-or-more test written as tickets > 4.
Mark yourself: how many marks did you get?/ 5 - Question 9Practice question · J277/02 style3 marks
(a) State one difference between a function and a procedure. [1] (b) Look at this program.
01 procedure showTotal(a, b) 02 print(a + b) 03 endprocedure 04 function double(n) 05 return n * 2 06 endfunction 07 x = double(7) 08 showTotal(x, 6)State the value of x after line 07, and what is printed by line 08. [2]
Show mark scheme
(a) A function returns a value but a procedure does not (1) (b) x is 14 (1) Line 08 prints 20 (1). Method: 14 + 6 = 20.
Mark yourself: how many marks did you get?/ 3 - Question 10Practice question · J277/02 style4 marks
01 global total = 10 02 procedure addFive() 03 bonus = 5 04 total = total + bonus 05 endprocedure 06 addFive() 07 addFive() 08 print(total)(a) State the value that is printed. [1] (b) Identify one local variable and one global variable in the program. [2] (c) Give one reason why programmers use local variables where they can. [1]
Show mark scheme
(a) 20 (1). Method: total starts at 10. The first call makes it 15 and the second call makes it 20. (b) Local variable: bonus (1). Global variable: total (1). (c) They cannot be changed by other parts of the program by accident / the same name can be reused in other sub programs / the memory is freed when the sub program ends (1)
Mark yourself: how many marks did you get?/ 4 - Question 11Practice question · J277/02 style4 marks
In a board game a player rolls a six-sided die. They win a bonus if the die shows 5 or 6. Write a program that rolls the die using a random number, then prints "Bonus" if the roll is 5 or 6 and prints "No bonus" if it is not. Write your answer in the OCR Exam Reference Language or a high-level programming language.
Show mark scheme
roll = random(1, 6) // (1 for random with limits 1 and 6, 1 for storing it in a variable) if roll >= 5 then // (1) print("Bonus") else print("No bonus") // (1 for both outputs in the right branches) endifAccept roll == 5 OR roll == 6. Accept roll > 4.
Mark yourself: how many marks did you get?/ 4 - Question 12Practice question · J277/02 style6 marks
A file called "names.txt" holds one name on each line. Write a program that reads every name in the file. It must print each name that has more than 5 characters, and at the end print how many such names there were. Write your answer in the OCR Exam Reference Language or a high-level programming language.
Show mark scheme
count = 0 nameFile = open("names.txt") // (1 for opening the file) while NOT nameFile.endOfFile() // (1 for a loop that stops at the end of the file) name = nameFile.readLine() // (1 for reading a line inside the loop and storing it) if name.length > 5 then // (1 for a correct test of the length) print(name) count = count + 1 // (1 for printing the name and adding one to the count) endif endwhile nameFile.close() print(count) // (1 for closing the file and printing the final count after the loop)Accept a count that starts at 0 and any equivalent file method or high-level language.
Mark yourself: how many marks did you get?/ 6
- •Practice answering questions under timed conditions
- •Check your answers against the mark scheme carefully
- •Focus on understanding the marking points, not just memorising answers
- •Come back to the questions you dropped marks on a few days later