Bird
0
0

Given this Python snippet, what will be printed?

medium📝 Analysis Q13 of 15
LLD - Design — Elevator System
Given this Python snippet, what will be printed?
class Request:
    def __init__(self, floor, direction):
        self.floor = floor
        self.direction = direction

r = Request(5, 'up')
print(r.floor, r.direction)
AError: missing self
Bfloor direction
C5 up
DNone None
Step-by-Step Solution
Solution:
  1. Step 1: Understand object creation and attribute assignment

    The Request object r is created with floor=5 and direction='up'. These are stored in attributes.
  2. Step 2: Print attributes

    Printing r.floor and r.direction outputs 5 and 'up' respectively.
  3. Final Answer:

    5 up -> Option C
  4. Quick Check:

    Attributes print as assigned = 5 up [OK]
Quick Trick: Print object attributes to see stored values [OK]
Common Mistakes:
MISTAKES
  • Expecting attribute names instead of values
  • Confusing class variables with instance variables
  • Assuming error without checking code carefully

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes