A. SyntaxError due to incorrect dictionary keys; fix keys to 'low' and 'high'
B. TypeError because object_center is None; fix by assigning a tuple to object_center
C. IndexError because green_filter keys are missing; add keys
D. No error; code runs correctly
Solution
Step 1: Identify the error cause
object_center is None, so accessing object_center[0] causes TypeError.
Step 2: Fix the error
Assign a tuple like (x, y) to object_center before using it in condition.
Final Answer:
TypeError because object_center is None; fix by assigning a tuple to object_center -> Option B
Quick Check:
None used as index causes TypeError [OK]
Hint: Check variable types before indexing [OK]
Common Mistakes:
Ignoring NoneType indexing error
Changing dictionary keys incorrectly
Assuming code runs without error
5. You want the drone to follow a yellow object but only if its detected center's y-coordinate is above 100. Which code snippet correctly implements this condition using color-based tracking?
A. if yellow_filter['lower'][0] <= object_center[0] <= yellow_filter['upper'][0] and object_center[1] > 100:
print('Following yellow object')
B. if yellow_filter['lower'][1] <= object_center[1] <= yellow_filter['upper'][1] and object_center[0] > 100:
print('Following yellow object')
C. if yellow_filter['lower'][0] <= object_center[1] <= yellow_filter['upper'][0] and object_center[0] > 100:
print('Following yellow object')
D. if yellow_filter['lower'][1] <= object_center[0] <= yellow_filter['upper'][1] and object_center[1] > 100:
print('Following yellow object')
Solution
Step 1: Understand HSV and coordinate roles
yellow_filter keys 'lower' and 'upper' define hue range at index 0; object_center[0] is x, object_center[1] is y.
Step 2: Check condition for hue and y-coordinate
Hue check uses object_center[0] between lower and upper hue; y-coordinate must be > 100.
Final Answer:
if yellow_filter['lower'][0] <= object_center[0] <= yellow_filter['upper'][0] and object_center[1] > 100:
print('Following yellow object') -> Option A
Quick Check:
Hue range on x and y > 100 condition = if yellow_filter['lower'][0] <= object_center[0] <= yellow_filter['upper'][0] and object_center[1] > 100:
print('Following yellow object') [OK]
Hint: Match hue with x, check y > 100 separately [OK]
Common Mistakes:
Mixing x and y coordinates in conditions
Using wrong indices for hue or saturation
Checking y-coordinate against hue range
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.