← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

Robotics lesson 23: If / else with sensors · Set 157 · 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 99 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  2. 2.🤖 What does an “if” let a robot do? (a) go faster always (b) skip all sensors (c) choose using a sensor (d) charge itself
  3. 3.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 28 cm. What does the robot do?
    (a) go forward (b) turn right
  4. 4.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 19 cm. What does the robot do?
    (a) go forward (b) turn right
  5. 5.🤖 A robot is 82 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  6. 6.🤖 A robot is 48 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  7. 7.🤖 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
  8. 8.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 6 cm. What does the robot do?
    (a) go forward (b) turn right
  9. 9.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 34 cm and the light reading is 40. What does the robot do?
    (a) go forward (b) turn left (c) stop
  10. 10.🤖 if (distance < 20) { turn right } else { go forward }
    The distance sensor reads 13 cm. What does the robot do?
    (a) go forward (b) turn right
  11. 11.🤖 if (distance < 15) { turn right } else { go forward }
    The distance sensor reads 14 cm. What does the robot do?
    (a) go forward (b) turn right
  12. 12.🤖 A robot is 105 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  13. 13.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 17 cm. What does the robot do?
    (a) go forward (b) turn right
  14. 14.🤖 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
  15. 15.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 21 cm. What does the robot do?
    (a) turn right (b) go forward
  16. 16.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 38 cm and the light reading is 40. What does the robot do?
    (a) stop (b) turn left (c) go forward
  17. 17.🤖 A robot is 107 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 39 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  19. 19.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 27 cm. What does the robot do?
    (a) go forward (b) turn right
  20. 20.🤖 A robot is 42 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  21. 21.🤖 if (distance < 20) { turn right } else { go forward }
    The distance sensor reads 12 cm. What does the robot do?
    (a) go forward (b) turn right
  22. 22.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 20 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 27 cm and the light reading is 75. What does the robot do?
    (a) go forward (b) turn left (c) stop
  24. 24.🤖 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
  25. 25.🤖 A robot is 32 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 40 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.🤖 A robot is 71 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  28. 28.🤖 if (distance < 30) { turn right } else { go forward }
    The distance sensor reads 26 cm. What does the robot do?
    (a) turn right (b) go forward
  29. 29.🤖 if (distance < 25) { turn right } else { go forward }
    The distance sensor reads 33 cm. What does the robot do?
    (a) turn right (b) go forward
  30. 30.🤖 A robot is 65 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 50 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 72 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How many times does it move forward?
  33. 33.🤖 if (distance < 20) { turn right } else { go forward }
    The distance sensor reads 30 cm. What does the robot do?
    (a) turn right (b) go forward
  34. 34.🤖 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
  35. 35.🤖 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
  36. 36.🤖 A robot is 106 cm from a wall. It runs:
    while (distance > 20) { forward 10 cm }
    stop
    How far from the wall does it stop (in cm)?
  37. 37.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 33 cm and the light reading is 50. What does the robot do?
    (a) go forward (b) stop (c) turn left
  38. 38.🤖 if (distance < 15) { stop } else if (light < 30) { turn left } else { go forward }
    The distance is 26 cm and the light reading is 10. What does the robot do?
    (a) turn left (b) stop (c) go forward
  39. 39.🤖 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
  40. 40.🤖 if (distance < 10) { turn right } else { go forward }
    The distance sensor reads 1 cm. What does the robot do?
    (a) turn right (b) go forward

Answer key

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

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