Two Kinds of Account

Python for AIMedium+10 XP+10

Two Kinds of Account

A banking app has two kinds of account. They share almost everything, so write the shared part once.

Account(owner, balance) (the parent):

  • deposit(amount) adds amount to the balance and returns the new balance.
  • withdraw(amount) takes amount out, but only if there's enough. If amount is bigger than the balance, nothing changes. Either way, it returns the balance.

Savings (a child of Account):

  • interest() returns 3% of the balance, rounded to 2 decimal places.

Wallet (a child of Account):

  • is_empty() returns True if the balance is exactly 0, otherwise False.

Neither child needs an __init__ of its own.

Then write two functions:

  • savings_interest(owner, deposits): make a Savings with a balance of 0, deposit each amount in the list in order, and return interest().
  • wallet_check(owner, start, spends): make a Wallet with balance start, try to withdraw each amount in order (too-big ones are skipped), and return [balance, is_empty()].

Examples

Savings("Ana", 1000).interest()
returns 30.0
owner = "Ana"
deposits = [100, 250]
returns 10.5
owner = "Raj"
start = 20
spends = [5, 15]
returns [0, True]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run