Chhetri AcademyGCSE & A level Paper Builder

1.2.3Arithmetic, relational and logical operators

Edexcel GCSE Computer Science (1CP2) · Computational thinking › Algorithms

Practise Arithmetic, relational and logical operators. 12 exam-style questions 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, relational and logical operators (Craig 'n' Dave Edexcel on YouTube) · Practise all of Algorithms

Sample questions

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

Question 1Easy5 marks
A teacher shares sweets equally between the children in a group. Any sweets left over are kept by the teacher.
01 sweets = 23
02 children = 4
03 each = sweets // children
04 left = sweets % children
05 print("Each child gets", each)
06 print(left, "sweets are left over")
(a) State the output of line 05.[1]
(b) State the output of line 06.[1]
(c) State the value of sweets / children.[1]
(d) State the value of children ** 2.[1]
(e) Give a reason why the programmer used // rather than / in line 03.[1]
Show the answer and mark scheme
(a) Answer: Each child gets 5
  • Each child gets 5
(b) Answer: 3 sweets are left over
  • 3 sweets are left over
(c) Answer: 5.75
  • 5.75
(d) Answer: 16
  • 16
(e) Answer: // gives only the whole-number part of the division (5), because each child must get a whole number of sweets; / would give 5.75.
  • // gives only the whole-number part of the division, because the sweets cannot be split (/ would give 5.75)
Question 2Medium4 marks
This program converts a number of seconds into minutes and seconds.
01 total = int(input("Enter a number of seconds: "))
02 minutes = total // 60
03 seconds = total % 60
04 print(minutes, "minutes and", seconds, "seconds")
(a) State the values output for minutes and seconds when the user enters 200.[2]
(b) Explain how the modulus operator can be used to check whether a whole number is even.[2]
Show the answer and mark scheme
(a) Answer: 3 minutes and 20 seconds
  • minutes: 3
  • seconds: 20
(b) Answer: number % 2 gives the remainder after dividing by 2; a remainder of 0 means the number is even.
  • the number % 2 gives the remainder when the number is divided by 2
  • if the remainder is 0, the number is even (otherwise it is odd)
Question 3Hard5 marks
A three-digit whole number is stored in the variable number.
(a) Write an algorithm, in Python, that calculates and outputs the sum of the three digits of number. For example, if number is 472, the output is 13.
You must use integer division and modulus.[4]
(b) State the value of 472 // 10 % 10.[1]
Show the answer and mark scheme
(a) Answer:
hundreds = number // 100
tens = (number // 10) % 10
units = number % 10
print(hundreds + tens + units)
  • hundreds digit found with number // 100
  • tens digit found with (number // 10) % 10 / (number % 100) // 10
  • units digit found with number % 10
  • adds the three digits and outputs the result
(b) Answer: 7
  • 7

Worked solution: // and % are worked out from left to right: 472 // 10 = 47, then 47 % 10 = 7.

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