Bird
0
0

An AI agent code snippet: if sensor == 'motion' then action = 'alert' else action = 'wait'. The code throws an error. What is the likely cause?

medium📝 Analysis Q6 of 15
AI for Everyone - AI Trends and Future
An AI agent code snippet: if sensor == 'motion' then action = 'alert' else action = 'wait'. The code throws an error. What is the likely cause?
AMissing parentheses around condition
BIncorrect variable names
CUsing 'then' instead of ':' in Python
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Identify language syntax rules

    Python uses ':' after if condition, not 'then'.
  2. Step 2: Check code for syntax errors

    Using 'then' causes syntax error in Python.
  3. Final Answer:

    Using 'then' instead of ':' in Python -> Option C
  4. Quick Check:

    Python if needs ':' not 'then' [OK]
Quick Trick: Python if statements use ':' not 'then' [OK]
Common Mistakes:
  • Confusing Python with other languages
  • Ignoring syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AI for Everyone Quizzes