Robotics: Loops and Conditions
שאלות 10
מפתח התשובות מוצג למורים מחוברים.
-
Choosing the right loop
A robot should keep moving forward as long as its front sensor does not detect a wall, and it does not know in advance how many steps this will take. Which programming structure is most suitable?
A function that is defined but never called
An if-else statement with no loop
A while loop that checks a condition
A for loop that repeats a fixed number of times
Think about a repetition structure that depends on a condition that may change during the run, not on a known count. -
Counting repeats in a for loop
A robot program contains a for loop that repeats the block 'move forward 10 cm' exactly 5 times. How many times is the block 'move forward 10 cm' executed in total?
10
4
5
6
Count how many repetitions the loop is set to perform, and remember that the loop body runs once per repetition. -
The else branch
In a robot program, an if-else statement checks whether the light sensor reading is below 30. In which situation is the else branch executed?
Only when the condition is True
Every time, before the if branch
Only when the condition is False
Only when the program is first started
Consider what happens to the else branch when the if condition does not hold. -
Behaviour of a while True loop
A robot program contains the loop 'while True: move forward' and no statement inside the loop stops it. What is the expected behaviour of the robot?
It moves forward until the program is stopped by the user or an external event
It turns off its motors after 10 seconds by default
It produces an error before the first movement
It moves forward once and then stops automatically
A loop whose condition never becomes False keeps repeating. Think about what can end such a loop. -
Nested loops
A robot program has an outer loop that repeats 3 times. Inside it, an inner loop repeats 2 times, and the inner loop body is 'blink the light'. How many times is 'blink the light' executed in total?
5
9
12
6
For each repetition of the outer loop, the inner loop runs completely. Multiply the two repeat counts. -
-
When the while condition is checked
In a while loop, when is the loop condition checked?
After the whole program has finished
Only after the loop body has run once
Only once, when the program starts
Before each repetition, including the first one
Think about whether the robot must check the condition before entering the loop body for the first time. -
Why use a loop
A student wants the robot to drive around a square. Instead of writing four separate 'move forward 20 cm' and 'turn right 90 degrees' pairs, the student uses a loop that repeats them 4 times. What is the main benefit of this approach?
The robot can drive in a circle without any turning
The program is shorter and easier to change or correct
The robot becomes faster than with separate commands
The robot no longer needs sensors
Compare how much code is needed and how many places must be edited if the square's side length changes. -
Combining loops and conditions
A line-following robot must keep checking its light sensor for as long as the program runs. If the sensor sees black, it moves forward; otherwise, it turns right to find the line again. Which combination of structures best describes this program?
An if statement placed outside any loop
A single for loop without any conditions
A while loop containing an if-else statement
Two separate functions with no repetition
The robot must repeat its checking over time, and it must choose between two actions at each check. -
Negating a Boolean condition
A robot's variable obstacle_detected is True when an obstacle is in front of it. Which condition should be used so that the robot moves forward only when there is no obstacle?
obstacle_detected or obstacle_detected
obstacle_detected
obstacle_detected and not obstacle_detected
not obstacle_detected
You need a condition that is True exactly when the Boolean variable is False. Think about which logical operator reverses a Boolean value.
פרטים
- מקצועות
- מדעי המחשב
- קהל יעד
- חטיבת ביניים · כיתות ז׳–ט׳
- רמת קושי
- 5 מתוך 10
- שפה
- אנגלית
- מי יכול לראות
- כולם
- נוצר באמצעות AI
- Claude Haiku 5.5
- נוצר
תגובות