← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

Robotics lesson 23: If / else with sensors · Set 134 · 40 questions
TalentJR

Robot tip (True → if, false → else): Put the reading into the condition: true → the if part, false → the else part. < means strictly less; an equal reading makes it false. else if: check the conditions from the top; the first true one wins. while: repeat until the condition is false.

NameDateTime takenScore ___ / 40
  1. 1.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 20 cm and the light reading is 40. What does the robot do?
    (a) go forward (b) turn left (c) stop
  2. 2.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 6 cm. What does the robot do?
    (a) go forward (b) turn right
  3. 3.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 19 cm. What does the robot do?
    (a) go forward (b) turn right
  4. 4.🤖 A robot is 77 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  5. 5.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 11 cm. What does the robot do?
    (a) turn right (b) go forward
  6. 6.🤖 A robot is 76 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  7. 7.🤖 What does an “if” let a robot do? (a) go faster always (b) skip all sensors (c) choose using a sensor (d) charge itself
  8. 8.🤖 In “if (distance < 20)”, what runs when the distance is exactly 20? (a) both parts (b) the else part (c) the if part (d) neither part
  9. 9.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 6 cm and the light reading is 20. What does the robot do?
    (a) go forward (b) turn left (c) stop
  10. 10.🤖 if (distance < 20) { turn right } else { go forward }
    The distance sensor reads 12 cm. What does the robot do?
    (a) go forward (b) turn right
  11. 11.🤖 A robot is 49 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  12. 12.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 27 cm. What does the robot do?
    (a) turn right (b) go forward
  13. 13.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 5 cm. What does the robot do?
    (a) turn right (b) go forward
  14. 14.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 36 cm and the light reading is 85. What does the robot do?
    (a) turn left (b) go forward (c) stop
  15. 15.🤖 if (bumper is pressed) { back up and turn right } else { go forward }
    The bumper is pressed. What does the robot do?
    (a) back up and turn right (b) go forward
  16. 16.🤖 if (bumper is pressed) { back up and turn right } else { go forward }
    The bumper is not pressed. What does the robot do?
    (a) back up and turn right (b) go forward
  17. 17.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 15 cm. What does the robot do?
    (a) go forward (b) turn right
  18. 18.🤖 A robot is 98 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  19. 19.🤖 if (distance < 20) { turn right } else { go forward }
    The distance sensor reads 32 cm. What does the robot do?
    (a) go forward (b) turn right
  20. 20.🤖 if (bumper is pressed) { back up and turn left } else { go forward }
    The bumper is pressed. What does the robot do?
    (a) go forward (b) back up and turn left
  21. 21.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 7 cm and the light reading is 35. What does the robot do?
    (a) stop (b) go forward (c) turn left
  22. 22.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 10 cm and the light reading is 40. What does the robot do?
    (a) turn left (b) go forward (c) stop
  23. 23.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 22 cm. What does the robot do?
    (a) go forward (b) turn right
  24. 24.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 33 cm and the light reading is 80. What does the robot do?
    (a) turn left (b) go forward (c) stop
  25. 25.🤖 Obstacle avoiding: what should a robot do when something is close? (a) speed up (b) stop or turn away (c) push it hard (d) close its eyes
  26. 26.🤖 A robot is 33 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  27. 27.🤖 if (bumper is pressed) { back up and turn left } else { go forward }
    The bumper is not pressed. What does the robot do?
    (a) back up and turn left (b) go forward
  28. 28.🤖 A robot is 99 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  29. 29.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 28 cm and the light reading is 30. What does the robot do?
    (a) stop (b) go forward (c) turn left
  30. 30.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 4 cm. What does the robot do?
    (a) turn right (b) go forward
  31. 31.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 30 cm and the light reading is 85. What does the robot do?
    (a) go forward (b) turn left (c) stop
  32. 32.🤖 A robot is 34 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  33. 33.🤖 A robot is 104 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  34. 34.🤖 A robot is 59 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  35. 35.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 34 cm. What does the robot do?
    (a) go forward (b) turn right
  36. 36.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 42 cm. What does the robot do?
    (a) go forward (b) turn right
  37. 37.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 10 cm and the light reading is 65. What does the robot do?
    (a) go forward (b) stop (c) turn left
  38. 38.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 32 cm and the light reading is 65. What does the robot do?
    (a) turn left (b) go forward (c) stop
  39. 39.🤖 A robot is 70 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  40. 40.🤖 A robot is 79 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?

Answer key

  1. go forward
  2. turn right
  3. go forward
  4. 17
  5. go forward
  6. 6
  7. choose using a sensor
  8. the else part
  9. stop
  10. turn right
  11. 3
  12. turn right
  13. turn right
  14. go forward
  15. back up and turn right
  16. go forward
  17. go forward
  18. 18
  19. go forward
  20. back up and turn left
  21. stop
  22. stop
  23. turn right
  24. go forward
  25. stop or turn away
  26. 13
  27. go forward
  28. 8
  29. go forward
  30. turn right
  31. go forward
  32. 2
  33. 14
  34. 4
  35. go forward
  36. go forward
  37. stop
  38. go forward
  39. 5
  40. 19

Free robotics lessons, practice and worksheets at talentjr.in/robotics-for-kids