HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /A robot vacuum is controlled by this pseudocode…
HardComputer ScienceHigh School (9–10)Computer Science › Automated and Emerging TechnologiesNumericalConceptualIGCSE

A robot vacuum is controlled by this pseudocode…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

A robot vacuum is controlled by this pseudocode. The proximity sensor gives the distance to the nearest object in centimetres.

pseudocode
CONSTANT TooClose ← 20
Turns ← 0
FOR Count ← 1 TO 8
    INPUT Distance
    IF Distance <= TooClose
      THEN
        OUTPUT "Turn"
        Turns ← Turns + 1
      ELSE
        OUTPUT "Forward"
    ENDIF
NEXT Count
OUTPUT Turns

The eight readings are 65, 42, 20, 18, 50, 21, 9 and 33.

  1. Trace the program: write the output for each reading and the last value output.
  1. Which characteristic of a robot does this program show, and how could the owner make the robot turn earlier?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

A robot has three characteristics: a mechanical structure or framework; electrical components, such as sensors, microprocessors and actuators; and it is programmable. A machine needs all three. A remote-controlled toy is not programmable, and a chat program has no mechanical structure, so neither is a robot.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

(a) Go through the readings one at a time, testing Distance <= 20.

  • 656565: Forward
  • 424242: Forward
  • 202020: Turn (equal to 202020 counts), so Turns becomes 111
  • 181818: Turn, Turns becomes 222
  • 505050: Forward
  • 212121: Forward (212121 is not 202020 or less)
  • 999: Turn, Turns becomes 333
  • 333333: Forward

The last line outputs Turns, which is 333.

(b) It shows that the robot is programmable: its behaviour comes from a stored program. To make it turn earlier, the owner changes the constant to a larger value, such as CONSTANT TooClose ← 30.

Watch out. With < instead of <=, the reading 202020 would not cause a turn, and the answer would be 222.

Log in to save this for later
← All Problems
← A small robot on a test bench drives at 0.25 m/s towards a wall 3.2 m away…A car maker plans to replace the workers who paint car bodies with painting robots… →
More onComputer Science › Automated and Emerging Technologies

Discussion (0)

Log in to join the discussion.

Loading…

More on this topic

  1. A filter calls an email unwanted when its score is greater than its dividing line T…Hard
  2. A bank wants software to decide which card payments might be fraud…Hard
  3. A learning filter is given eight emails that users have labelled…Medium
  4. An email service has a filter that moves unwanted messages into a separate folder…Medium
  5. A health centre in a remote area uses an expert system to help a nurse decide whether a patient…Hard
All problems on this topic →