Bird
0
0

How can you represent a simple rule-based decision system in Python to decide actions based on weather conditions?

easy📝 Factual Q3 of 15
AI for Everyone - What is Artificial Intelligence
How can you represent a simple rule-based decision system in Python to decide actions based on weather conditions?
Arules = {'rainy': 'take umbrella', 'sunny': 'wear sunglasses'} action = rules.get(weather, 'stay indoors')
Bdef predict(weather): return 'take umbrella' if weather == 'rainy' else 'wear sunglasses'
Cmodel = train(weather_data) prediction = model.predict(weather)
Dif weather == 'rainy': action = 'wear sunglasses' else: action = 'take umbrella'
Step-by-Step Solution
Solution:
  1. Step 1: Identify rule-based representation

    Rule-based systems use explicit mappings from conditions to actions.
  2. Step 2: Check Python syntax

    Using a dictionary with get() provides a clear rule-based lookup with a default.
  3. Final Answer:

    Using a dictionary with get() for rules -> Option A
  4. Quick Check:

    Dictionary lookup for rules [OK]
Quick Trick: Use dict.get() for default rule-based actions [OK]
Common Mistakes:
MISTAKES
  • Confusing ML model training with rule-based logic
  • Incorrect if-else logic reversing actions
  • Not providing a default action for unknown inputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AI for Everyone Quizzes