← If / else with sensors lesson New set →

Robotics Worksheet: Robot If / Else

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

Answer key

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

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