The steps are {'battery': True, 'motors': True, 'gps': False} so values are [True, True, False].
Step 2: Evaluate all() function on values
all() returns True only if all values are True; here one is False, so result is False.
Final Answer:
False -> Option A
Quick Check:
all([True, True, False]) = False [OK]
Hint: all() returns False if any value is False [OK]
Common Mistakes:
Assuming all() returns True if some values are True
Confusing dictionary keys with values
Expecting print to show dictionary instead of boolean
4. Identify the error in this pre-flight checklist code:
class PreFlight:
def __init__(self):
self.steps = {'battery': True, 'motors': True}
def check_all(self):
for step in self.steps:
if self.steps[step] = False:
return False
return True
pf = PreFlight()
print(pf.check_all())
medium
A. Indentation error in for loop
B. Missing return statement in check_all method
C. Incorrect dictionary initialization syntax
D. Syntax error: '=' used instead of '==' in if condition
Solution
Step 1: Check the if condition syntax
The line 'if self.steps[step] = False:' uses '=' which is assignment, not comparison.
Step 2: Correct syntax for comparison
It should be '==' to compare values, so 'if self.steps[step] == False:' is correct.
Final Answer:
Syntax error: '=' used instead of '==' in if condition -> Option D
Quick Check:
Use '==' for comparison, '=' causes syntax error [OK]
Hint: Use '==' for comparison, not '=' [OK]
Common Mistakes:
Using '=' instead of '==' in conditions
Forgetting to return a value
Misindenting loops or blocks
5. You want to extend the pre-flight checklist to automatically add a new step only if the drone has a camera. Which code snippet correctly adds this conditional step inside the class?
hard
A. self.steps['camera'] = self.has_camera
B. if self.has_camera == True:
self.steps['camera'] = True
C. self.steps['camera'] = True if self.has_camera else None
D. self.steps.append('camera') if self.has_camera else None
Solution
Step 1: Understand conditional addition of step
We add 'camera' step only if self.has_camera is True.
Step 2: Check syntax for condition and dictionary update
if self.has_camera == True:
self.steps['camera'] = True uses 'if self.has_camera == True:' and sets self.steps['camera'] = True, which is clear and correct.
Final Answer:
if self.has_camera == True:
self.steps['camera'] = True -> Option B
Quick Check:
Use if condition and dict assignment for conditional step [OK]
Hint: Use if condition with dict assignment for conditional steps [OK]