Chhetri AcademyGCSE & A level Paper Builder

Arithmetic, comparison and Boolean operators

OCR GCSE Computer Science (J277) · Algorithms and programming (Paper 2) › Programming fundamentals › Programming fundamentals

Practise Arithmetic, comparison and Boolean operators. 12 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.

Build a paper on this topic

▶ Watch videos on Arithmetic, comparison and Boolean operators (Craig 'n' Dave OCR on YouTube) · Practise all of Programming fundamentals

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

State the value of 17 MOD 5.
2
State the value of 20 MOD 6.
2

Sample questions

Written for this site in the style of OCR exam questions. They are not taken from real past papers.

Question 1Easy4 marks
(a) State the value of 17 MOD 5.[1]
(b) State the value of 17 DIV 5.[1]
(c) State the value of 2 ^ 4.[1]
(d) Which operator means not equal to?
Tick (✓) one box.[1]
  • ==
  • !=
  • <=
  • =
Show the answer and mark scheme
(a) Answer: 2
  • 2
(b) Answer: 3
  • 3
(c) Answer: 16
  • 16
(d) Answer: !=
Question 2Medium5 marks
(a) A program should output Even when the integer num is even. Complete the condition in this line of code.
if ...................... then
[2]
(b) A program sets a = 6, b = 10 and c = 3. State whether each expression is True or False.
  • a < b AND c > 5
  • a < b OR c > 5
  • NOT (a == 6)
[3]
Show the answer and mark scheme
(a) Answer: num MOD 2 == 0
  • num MOD 2
  • == 0
(b) Answer: False, True, False
  • False
  • True
  • False
Question 3Hard6 marks
A theme park ride has these rules:
  • every rider must be at least 120 cm tall
  • riders under 14 years old must be with an adult.
A program uses the variables height (integer, in cm), age (integer) and withAdult (Boolean). In this language AND is evaluated before OR.
(a) Write a Boolean expression that is True only when a rider is allowed on the ride.[3]
(b) State whether a rider with height = 125, age = 12 and withAdult = false is allowed on the ride.[1]
(c) A programmer writes the expression without brackets:
height >= 120 AND age >= 14 OR withAdult
Give values of height, age and withAdult for which this expression gives the wrong result, and explain why.[2]
Show the answer and mark scheme
(a) Answer: height >= 120 AND (age >= 14 OR withAdult == true)
  • height >= 120
  • AND (age >= 14 OR withAdult == true)
  • brackets (or equivalent structure) so that the height check applies in every case
(b) Answer: Not allowed (False)
  • not allowed / False
(c)
  • any height below 120 with withAdult true, e.g. 110, 10, true
  • AND is done first, so the expression becomes (height >= 120 AND age >= 14) OR withAdult, which is True for a rider who is too short

Related subtopics

Stuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.

Book a free trial