← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

Answer key

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

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