Bird
0
0

What is the output of this code snippet?

medium📝 Predict Output Q5 of 15
Agentic AI - Agent Safety and Guardrails
What is the output of this code snippet?
def validate_age(age):
    if not isinstance(age, int) or age < 0 or age > 120:
        return False
    return True

print(validate_age('25'))
AFalse
BTrue
CError
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Check input type and value

    Input is string '25', not int, so isinstance check fails.
  2. Step 2: Evaluate condition and return

    Because type check fails, function returns False.
  3. Final Answer:

    False -> Option A
  4. Quick Check:

    Type check fails = False output [OK]
Quick Trick: Type must match expected for validation True [OK]
Common Mistakes:
  • Assuming string '25' passes as int
  • Expecting True without type check
  • Thinking code throws error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes