Practise Sequence, selection and iteration. 11 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.
Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.
Look at this program.
01 total = 0
02 for i = 1 to 5
03 num = int(input("Enter a number"))
04 total = total + num
05 next i
06 if total > 100 then
07 print("Large")
08 else
09 print("Small")
10 endif
Identify the line number where selection starts.
06
Name the type of loop that repeats a set number of times.
Count-controlled loop (e.g. a for loop)
Sample questions
Written for this site in the style of OCR exam questions. They are not taken from real past papers.
Question 1Easy4 marks
Look at this program.
01 total = 0
02 for i = 1 to 5
03 num = int(input("Enter a number"))
04 total = total + num
05 next i
06 if total > 100 then
07 print("Large")
08 else
09 print("Small")
10 endif
(a) Identify the line number where selection starts.[1]
(b) Identify the line number where iteration starts.[1]
(c) State the name of the programming construct in which instructions are carried out one after another, in order.[1]
(d) State how many numbers the user is asked to enter.[1]
Show the answer and mark scheme
(a)Answer: 06
06 / line 6
(b)Answer: 02
02 / line 2
(c)Answer: Sequence
sequence
(d)Answer: 5
5
Question 2Medium5 marks
Look at this algorithm.
01 for k = 3 to 15 step 4
02 print(k)
03 next k
(a) State the output of the algorithm.[1]
(b) Rewrite the algorithm using a while loop so that it produces the same output.[3]
(c) Line 01 is changed to for k = 3 to 14 step 4. State how many times the loop now runs.[1]
Show the answer and mark scheme
(a)Answer: 3, 7, 11, 15
3, 7, 11, 15
(b)Answer:
k = 3
while k <= 15
print(k)
k = k + 4
endwhile
sets k to 3 before the loop
loop condition k <= 15 (or k < 16 / k < 19)
outputs k and then adds 4 to k inside the loop
(c)Answer: 3 (k = 3, 7, 11)
3
Question 3Hard8 marks
A cinema charges for tickets as follows.
On Tuesdays every ticket costs £6.00, whatever the age of the customer.
On other days, customers under 12 pay £5.50, customers aged 12 to 17 pay £7.00 and customers aged 18 or over pay £10.50.
(a) Write a program that asks the user to enter the day and the customer's age, and outputs the price of the ticket. You must use either OCR Exam Reference Language or a high-level programming language that you have studied.[6]
(b) State four ages that should be tested on a Wednesday to check the boundaries of the age bands.[2]
Show the answer and mark scheme
(a)Answer:
day = input("Enter the day")
age = int(input("Enter the age"))
if day == "Tuesday" then
price = 6.00
elseif age < 12 then
price = 5.50
elseif age <= 17 then
price = 7.00
else
price = 10.50
endif
print(price)
inputs the day and the age (age as an integer)
checks for Tuesday before (or separately from) the age checks
gives 6.00 on a Tuesday
gives 5.50 when the age is less than 12
gives 7.00 for ages 12 to 17 inclusive
gives 10.50 for ages 18 and over (and outputs the price)