← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

Answer key

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

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