← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

Robotics lesson 23: If / else with sensors · Set 253 · 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 (bumper is pressed) { back up and turn left } else { go forward }
    The bumper is pressed. What does the robot do?
    (a) back up and turn left (b) go forward
  2. 2.🤖 Obstacle avoiding: what should a robot do when something is close? (a) stop or turn away (b) push it hard (c) speed up (d) close its eyes
  3. 3.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 27 cm. What does the robot do?
    (a) turn right (b) go forward
  4. 4.🤖 In “if (distance < 20)”, what runs when the distance is exactly 20? (a) the if part (b) neither part (c) the else part (d) both parts
  5. 5.🤖 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
  6. 6.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 12 cm and the light reading is 65. What does the robot do?
    (a) stop (b) turn left (c) go forward
  7. 7.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 14 cm. What does the robot do?
    (a) go forward (b) turn right
  8. 8.🤖 if (bumper is pressed) { back up and turn right } else { go forward }
    The bumper is not pressed. What does the robot do?
    (a) go forward (b) back up and turn right
  9. 9.🤖 What does an “if” let a robot do? (a) go faster always (b) skip all sensors (c) charge itself (d) choose using a sensor
  10. 10.🤖 A robot is 62 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  11. 11.🤖 A robot is 40 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  12. 12.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 37 cm and the light reading is 20. What does the robot do?
    (a) go forward (b) turn left (c) stop
  13. 13.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 16 cm and the light reading is 55. What does the robot do?
    (a) turn left (b) go forward (c) stop
  14. 14.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 21 cm and the light reading is 25. What does the robot do?
    (a) turn left (b) go forward (c) stop
  15. 15.🤖 A robot is 83 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  16. 16.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 6 cm and the light reading is 85. What does the robot do?
    (a) go forward (b) stop (c) turn left
  17. 17.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 33 cm and the light reading is 50. What does the robot do?
    (a) stop (b) turn left (c) go forward
  18. 18.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 10 cm and the light reading is 10. What does the robot do?
    (a) turn left (b) go forward (c) stop
  19. 19.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 11 cm. What does the robot do?
    (a) turn right (b) go forward
  20. 20.🤖 A robot is 103 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  21. 21.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 35 cm. What does the robot do?
    (a) go forward (b) turn right
  22. 22.🤖 A robot is 42 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  23. 23.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 38 cm and the light reading is 65. What does the robot do?
    (a) go forward (b) stop (c) turn left
  24. 24.🤖 A robot is 108 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  25. 25.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 5 cm and the light reading is 75. What does the robot do?
    (a) stop (b) go forward (c) turn left
  26. 26.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 15 cm and the light reading is 20. What does the robot do?
    (a) turn left (b) stop (c) go forward
  27. 27.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 16 cm. What does the robot do?
    (a) go forward (b) turn right
  28. 28.🤖 A robot is 76 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  29. 29.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 18 cm and the light reading is 25. What does the robot do?
    (a) go forward (b) stop (c) turn left
  30. 30.🤖 A robot is 68 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  31. 31.🤖 A robot is 43 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  32. 32.🤖 A robot is 71 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  33. 33.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 7 cm and the light reading is 55. What does the robot do?
    (a) go forward (b) stop (c) turn left
  34. 34.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 37 cm and the light reading is 40. What does the robot do?
    (a) turn left (b) go forward (c) stop
  35. 35.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 23 cm and the light reading is 65. What does the robot do?
    (a) go forward (b) turn left (c) stop
  36. 36.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 22 cm. What does the robot do?
    (a) turn right (b) go forward
  37. 37.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 19 cm and the light reading is 60. What does the robot do?
    (a) stop (b) turn left (c) go forward
  38. 38.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 31 cm and the light reading is 20. What does the robot do?
    (a) stop (b) turn left (c) go forward
  39. 39.🤖 A robot is 57 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  40. 40.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 31 cm. What does the robot do?
    (a) turn right (b) go forward

Answer key

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

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