Deposits

Report a typo

Bank accounts can be of different types. We have created an abstract class Account that can serve as a template for other accounts. It has two methods, abstract method add_money and regular method add_interest.

Your task is to create subclasses SavingsAccount and Deposit:

  • SavingsAccount: we can add no less than $10 at a time. The interest rate is zero, so no percentage of the sum is paid back to the account.
  • Deposit: we can add no less than $50 at a time. Deposits have a fixed interest rate, so a percentage of the money is paid back to the account.

Below is an example of how these classes should behave. Note that this is just an example, not the exact check code!

new_savings = SavingsAccount(50)
new_savings.add_money(5)  # prints the following message:
# Cannot add to SavingsAccount: amount too low.
new_savings.add_money(30)
new_savings.add_interest()
print(new_savings.sum)
# 80

new_deposit = Deposit(60, 0.078)
new_deposit.add_money(30)  # prints the following message:
# Cannot add to Deposit: amount too low.
new_deposit.add_money(70)
new_deposit.add_interest()
print(new_deposit.sum)
# 140.14
Write a program in Python 3
from abc import ABC, abstractmethod


class Account(ABC):
def __init__(self, starting_sum, interest=None):
self.sum = starting_sum
self.interest = interest

@abstractmethod
def add_money(self, amount):
...

def add_interest(self):
...


# create SavingsAccount and Deposit
___

Create a free account to access the full topic