Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
Python - Conditional Statements
What will be the output of this code?
age = 20
has_id = False
if age >= 18 and has_id:
    print('Allowed')
else:
    print('Denied')
ASyntaxError
BAllowed
CDenied
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate each condition

    age >= 18 is True since 20 >= 18, but has_id is False.
  2. Step 2: Apply 'and' operator

    True and False is False, so the else block runs.
  3. Final Answer:

    Denied -> Option C
  4. Quick Check:

    True and False = False [OK]
Quick Trick: Both conditions must be true for 'and' to print Allowed [OK]
Common Mistakes:
MISTAKES
  • Assuming one True is enough with 'and'
  • Confusing 'and' with 'or'
  • Ignoring boolean value of variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes