← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

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