Bird
0
0

Find the error in this ternary expression:

medium📝 Debug Q14 of 15
Python - Conditional Statements
Find the error in this ternary expression:
result = "Pass" if score > 50 else "Fail" else "Invalid"
ASyntaxError due to multiple else keywords
BNo error, code runs fine
CTypeError because of string comparison
DNameError because score is undefined
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the ternary expression structure

    The expression has two else keywords, which is invalid syntax in Python ternary expressions.
  2. Step 2: Understand Python ternary rules

    Python ternary expressions allow only one else part; multiple else cause SyntaxError.
  3. Final Answer:

    SyntaxError due to multiple else keywords -> Option A
  4. Quick Check:

    Only one else allowed in ternary [OK]
Quick Trick: Only one else per ternary expression [OK]
Common Mistakes:
MISTAKES
  • Trying to chain else without nesting
  • Assuming multiple else are allowed
  • Ignoring syntax error messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes