Bird
Raised Fist0

What will be the output of this code?

medium📝 Analysis Q5 of Q15
LLD - Design — Splitwise (Expense Sharing)
What will be the output of this code?
class Expense:
    def __init__(self, amount, paid_by):
        self.amount = amount
        self.paid_by = paid_by

expense = Expense(100, 'Bob')
print(expense.paid_by)
A'Bob'
B100
CNone
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand Expense class attributes

    paid_by is set to 'Bob' during initialization.
  2. Step 2: Print expense.paid_by value

    Output will be the string 'Bob'.
  3. Final Answer:

    'Bob' -> Option A
  4. Quick Check:

    Paid_by attribute = 'Bob' [OK]
Quick Trick: Print attribute value assigned in constructor [OK]
Common Mistakes:
MISTAKES
  • Printing amount instead of paid_by
  • Expecting numeric output
  • Syntax errors in print statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes