Bird
Raised Fist0

What will be the output of the following Python code?

medium📝 Analysis Q4 of Q15
LLD - Design — Elevator System
What will be the output of the following Python code?
class Floor:
    def __init__(self, number, is_accessible):
        self.number = number
        self.is_accessible = is_accessible

f = Floor(10, true)
print(f.number, f.is_accessible)
A10 true
Bnumber is_accessible
Cnull null
DError: missing arguments
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the class initialization

    The Floor class constructor takes two parameters and assigns them to instance variables.
  2. Step 2: Check the print statement

    Printing f.number and f.is_accessible will output the values passed during initialization.
  3. Step 3: Identify error in code

    Python boolean literals are capitalized: True not true. Using true causes a NameError.
  4. Final Answer:

    Error: missing arguments -> Option D
  5. Quick Check:

    Boolean literals must be capitalized in Python [OK]
Quick Trick: Use True/False in Python, not true/false [OK]
Common Mistakes:
MISTAKES
  • Using lowercase true/false instead of True/False
  • Confusing variable names
  • Assuming default values without initialization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes