← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

Robotics lesson 23: If / else with sensors · Set 96 · 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) the if part (c) neither part (d) both parts
  2. 2.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 5 cm. What does the robot do?
    (a) turn right (b) go forward
  3. 3.🤖 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
  4. 4.🤖 What does an “if” let a robot do? (a) go faster always (b) charge itself (c) skip all sensors (d) choose using a sensor
  5. 5.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 37 cm and the light reading is 10. What does the robot do?
    (a) turn left (b) go forward (c) stop
  6. 6.🤖 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
  7. 7.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 34 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) go forward (b) turn right
  9. 9.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 19 cm. What does the robot do?
    (a) turn right (b) go forward
  10. 10.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 10 cm and the light reading is 15. What does the robot do?
    (a) stop (b) turn left (c) go forward
  11. 11.🤖 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
  12. 12.🤖 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
  13. 13.🤖 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
  14. 14.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 30 cm. What does the robot do?
    (a) go forward (b) turn right
  15. 15.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 24 cm. What does the robot do?
    (a) go forward (b) turn right
  16. 16.🤖 A robot is 69 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  17. 17.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 13 cm. What does the robot do?
    (a) turn right (b) go forward
  18. 18.🤖 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
  19. 19.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 9 cm and the light reading is 55. What does the robot do?
    (a) go forward (b) stop (c) turn left
  20. 20.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 32 cm. What does the robot do?
    (a) turn right (b) go forward
  21. 21.🤖 A robot is 93 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  22. 22.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 25 cm and the light reading is 80. What does the robot do?
    (a) go forward (b) turn left (c) stop
  23. 23.🤖 A robot is 70 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.🤖 A robot is 44 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  25. 25.🤖 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
  26. 26.🤖 A robot is 51 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  27. 27.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 34 cm and the light reading is 45. What does the robot do?
    (a) stop (b) turn left (c) go forward
  28. 28.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 21 cm. What does the robot do?
    (a) turn right (b) go forward
  29. 29.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 8 cm and the light reading is 10. What does the robot do?
    (a) turn left (b) go forward (c) stop
  30. 30.🤖 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)?
  31. 31.🤖 A robot is 68 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.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 34 cm and the light reading is 60. What does the robot do?
    (a) stop (b) go forward (c) turn left
  33. 33.🤖 A robot is 80 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  34. 34.🤖 A robot is 64 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.🤖 A robot is 92 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 < 20) { turn right } else { go forward }
    The distance sensor reads 14 cm. What does the robot do?
    (a) turn right (b) go forward
  37. 37.🤖 A robot is 52 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  38. 38.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 14 cm and the light reading is 80. What does the robot do?
    (a) stop (b) turn left (c) go forward
  39. 39.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 24 cm and the light reading is 60. What does the robot do?
    (a) stop (b) turn left (c) go forward
  40. 40.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 18 cm. What does the robot do?
    (a) go forward (b) turn right

Answer key

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

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