← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

Robotics lesson 23: If / else with sensors · Set 66 · 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 (distance < 20) { turn right } else { go forward }
    The distance sensor reads 11 cm. What does the robot do?
    (a) turn right (b) go forward
  2. 2.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 34 cm and the light reading is 25. What does the robot do?
    (a) stop (b) go forward (c) turn left
  3. 3.🤖 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
  4. 4.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 3 cm. What does the robot do?
    (a) turn right (b) go forward
  5. 5.🤖 A robot is 81 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  6. 6.🤖 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
  7. 7.🤖 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
  8. 8.🤖 In “if (distance < 20)”, what runs when the distance is exactly 20? (a) both parts (b) the else part (c) neither part (d) the if part
  9. 9.🤖 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)?
  10. 10.🤖 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)?
  11. 11.🤖 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)?
  12. 12.🤖 A robot is 73 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.🤖 A robot is 42 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  14. 14.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 15 cm. What does the robot do?
    (a) turn right (b) go forward
  15. 15.🤖 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
  16. 16.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 10 cm. What does the robot do?
    (a) go forward (b) turn right
  17. 17.🤖 A robot is 34 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  18. 18.🤖 A robot is 68 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  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 20 cm and the light reading is 10. What does the robot do?
    (a) go forward (b) turn left (c) stop
  21. 21.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 8 cm and the light reading is 90. What does the robot do?
    (a) go forward (b) turn left (c) stop
  22. 22.🤖 A robot is 99 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  23. 23.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 32 cm and the light reading is 10. What does the robot do?
    (a) go forward (b) turn left (c) stop
  24. 24.🤖 A robot is 77 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 < 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) stop (b) go forward (c) turn left
  26. 26.🤖 A robot is 108 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  27. 27.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 28 cm and the light reading is 25. What does the robot do?
    (a) stop (b) go forward (c) turn left
  28. 28.🤖 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
  29. 29.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 17 cm and the light reading is 40. What does the robot do?
    (a) stop (b) turn left (c) go forward
  30. 30.🤖 A robot is 71 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.🤖 What does an “if” let a robot do? (a) go faster always (b) charge itself (c) choose using a sensor (d) skip all sensors
  32. 32.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 7 cm and the light reading is 20. What does the robot do?
    (a) turn left (b) go forward (c) stop
  33. 33.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 34 cm. What does the robot do?
    (a) go forward (b) turn right
  34. 34.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 11 cm. What does the robot do?
    (a) go forward (b) turn right
  35. 35.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 22 cm. What does the robot do?
    (a) turn right (b) go forward
  36. 36.🤖 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
  37. 37.🤖 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
  38. 38.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 17 cm. What does the robot do?
    (a) turn right (b) go forward
  39. 39.🤖 A robot is 54 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 80 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?

Answer key

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

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