Bird
Raised Fist0

Find the error in this object-oriented code:

medium📝 Debug Q7 of Q15
Python - Object-Oriented Programming Foundations
Find the error in this object-oriented code:
class Car:
    def __init__(self, model):
    self.model = model

c = Car('Tesla')
print(c.model)
AMissing parentheses in class definition
BIndentation error in __init__ method
CIncorrect print syntax
DWrong attribute name
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation inside __init__

    The line 'self.model = model' must be indented inside the __init__ method.
  2. Step 2: Identify the indentation error

    Without proper indentation, Python raises an IndentationError.
  3. Final Answer:

    Indentation error in __init__ method -> Option B
  4. Quick Check:

    Method body must be indented [OK]
Quick Trick: Indent method code inside class properly [OK]
Common Mistakes:
MISTAKES
  • Not indenting method body
  • Confusing class and function indentation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes