← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

Answer key

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

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