← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

Answer key

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

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