Bird
0
0

Consider this class:

hard📝 Application Q9 of 15
Python - Methods and Behavior Definition
Consider this class:
class BankAccount:
    def __init__(self, balance):
        self.balance = balance
    def deposit(self, amount):
        self.balance += amount
    def withdraw(self, amount):
        if amount <= self.balance:
            self.balance -= amount
        else:
            print('Insufficient funds')
    def get_balance(self):
        return self.balance

account = BankAccount(100)
account.deposit(50)
account.withdraw(30)
print(account.get_balance())

What is the output?
A100
B150
C120
DInsufficient funds
Step-by-Step Solution
Solution:
  1. Step 1: Trace balance changes

    Initial balance is 100, deposit adds 50 (total 150), withdraw subtracts 30 (total 120).
  2. Step 2: Print final balance

    The get_balance() method returns 120.
  3. Final Answer:

    120 -> Option C
  4. Quick Check:

    Balance after deposit and withdraw = 120 [OK]
Quick Trick: Track balance updates step-by-step [OK]
Common Mistakes:
  • Subtracting before adding
  • Ignoring insufficient funds check
  • Printing instead of returning balance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes