Bird
0
0

Find the error in this code:

medium📝 Debug Q7 of 15
Python - Advanced Exception Handling
Find the error in this code:
def validate_score(score):
    if score > 100:
        raise ValueError, 'Score too high'
    return score

validate_score(150)
AIncorrect syntax for raise statement; comma should be parentheses
BThe condition should be score < 100
CValueError cannot be raised
DNo error; code works fine
Step-by-Step Solution
Solution:
  1. Step 1: Review raise syntax

    Modern Python requires 'raise ExceptionType(message)' with parentheses.
  2. Step 2: Identify syntax error

    Using comma instead of parentheses causes syntax error.
  3. Final Answer:

    Incorrect syntax for raise statement; comma should be parentheses -> Option A
  4. Quick Check:

    Raise syntax uses parentheses, not commas [OK]
Quick Trick: Use parentheses in raise, not commas [OK]
Common Mistakes:
  • Using old-style raise syntax with commas
  • Changing condition incorrectly
  • Thinking ValueError cannot be raised

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes