Bird
Raised Fist0

Find the error in this code:

medium📝 Debug Q14 of Q15
Python - Methods and Behavior Definition
Find the error in this code:
class B:
    def start(self):
        self.middle()
    def middle(self):
        self.end()
    def end(self):
        print('Done')

b = B()
b.middle()
ANo output because start() is not called
BAttributeError because end() is not defined
CTypeError due to missing arguments
DNo error, prints 'Done'
Step-by-Step Solution
Solution:
  1. Step 1: Check method definitions

    All methods are defined correctly with self parameter.
  2. Step 2: Check method call

    b.middle() calls self.end(), which prints 'Done'. So output is 'Done' with no error.
  3. Final Answer:

    No error, prints 'Done' -> Option D
  4. Quick Check:

    Calling middle() runs end() correctly [OK]
Quick Trick: Trace calls from the method you invoke to see output [OK]
Common Mistakes:
MISTAKES
  • Expecting start() must be called first
  • Thinking end() is undefined
  • Confusing missing arguments error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes