← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

Answer key

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

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