Bird
0
0

Identify the error in this Elevator class snippet:

medium📝 Analysis Q14 of 15
LLD - Design — Elevator System
Identify the error in this Elevator class snippet:
class Elevator:
    def __init__(self, current_floor):
        self.current_floor = current_floor

    def move_to(self, floor):
        current_floor = floor
AIndentation error in move_to method
BMissing return statement in move_to method
CConstructor should not have parameters
DThe move_to method updates a local variable, not the elevator's floor
Step-by-Step Solution
Solution:
  1. Step 1: Analyze move_to method

    The method assigns current_floor = floor without self., so it changes a local variable only.
  2. Step 2: Understand instance variable update

    To update the elevator's floor, it should be self.current_floor = floor.
  3. Final Answer:

    The move_to method updates a local variable, not the elevator's floor -> Option D
  4. Quick Check:

    Missing self. means local variable used [OK]
Quick Trick: Use self. to update instance variables inside methods [OK]
Common Mistakes:
MISTAKES
  • Forgetting self. prefix
  • Thinking return is needed to update state
  • Assuming indentation is wrong without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes