← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

Answer key

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

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