Bird
0
0

What will be the output of this code snippet?

medium📝 Analysis Q5 of 15
LLD - Design — Elevator System
What will be the output of this code snippet?
class Elevator:
    def __init__(self):
        self.current_floor = 0
    def move_up(self):
        self.current_floor += 1

el = Elevator()
el.move_up()
el.move_up()
print(el.current_floor)
A0
B2
C1
DError: current_floor undefined
Step-by-Step Solution
Solution:
  1. Step 1: Initial value of current_floor

    Elevator starts at floor 0.
  2. Step 2: Two calls to move_up increment floor by 1 each

    After two calls, current_floor = 0 + 1 + 1 = 2.
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Increment current_floor twice = 2 [OK]
Quick Trick: Each move_up adds 1 to current_floor [OK]
Common Mistakes:
MISTAKES
  • Forgetting increments
  • Assuming initial floor is 1
  • Confusing method call effects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes