Accuracy is 0.85, threshold is 0.8, so 0.85 >= 0.8 is True.
Step 2: Assign comparison result to success
The boolean True is assigned to success.
Final Answer:
True -> Option A
Quick Check:
0.85 >= 0.8 = True [OK]
Hint: Check if accuracy meets or exceeds threshold [OK]
Common Mistakes:
Confusing value 0.85 with boolean True
Thinking comparison returns a number
Expecting an error from valid comparison
4. The following code is intended to check if an agent's success metric is above 90%, but it has a bug. What is the bug?
success_metric = 0.92
if success_metric = 0.9:
print('Agent succeeded')
medium
A. Missing colon ':' after if statement
B. Print statement syntax error
C. Incorrect variable name 'success_metric'
D. Using '=' instead of '==' in the if condition
Solution
Step 1: Identify the if statement syntax
In Python, '=' is for assignment, '==' is for comparison in conditions.
Step 2: Locate the bug in the if condition
The code uses '=' instead of '==' which causes a syntax error.
Final Answer:
Using '=' instead of '==' in the if condition -> Option D
Quick Check:
Use '==' for comparison in if [OK]
Hint: Use '==' to compare values in if statements [OK]
Common Mistakes:
Confusing '=' with '==' in conditions
Ignoring syntax errors from wrong operators
Assuming missing colon is the error
5. You want to define success criteria for an agent that completes tasks with at least 95% accuracy and finishes within 10 seconds. Which of the following is the best way to define this success criteria in code?
hard
A. success = (accuracy >= 0.95) and (time_taken <= 10)
B. success = accuracy > 0.95 or time_taken < 10
C. success = accuracy == 0.95 and time_taken == 10
D. success = accuracy >= 0.95 and time_taken > 10
Solution
Step 1: Understand the criteria requirements
The agent must have accuracy at least 95% and finish within 10 seconds.
Step 2: Translate criteria into logical conditions
Use '>=' for accuracy and '<=' for time, combined with 'and' to require both.
Step 3: Evaluate each option
success = (accuracy >= 0.95) and (time_taken <= 10) correctly uses 'and' and proper comparisons. success = accuracy > 0.95 or time_taken < 10 uses 'or' which allows passing if only one condition is met. success = accuracy == 0.95 and time_taken == 10 uses '==' which is too strict. success = accuracy >= 0.95 and time_taken > 10 allows time_taken > 10 which breaks the time limit.
Final Answer:
success = (accuracy >= 0.95) and (time_taken <= 10) -> Option A
Quick Check:
Both accuracy and time must meet thresholds [OK]
Hint: Use 'and' to combine all success conditions [OK]