-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavings_account.py
More file actions
33 lines (25 loc) · 1.37 KB
/
savings_account.py
File metadata and controls
33 lines (25 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Import the Account class from the Account.py file."""
from Account import Account
# Define a function for the Savings Account
def create_savings_account(balance, interest_rate, months):
"""Creates a savings account, calculates interest earned, and updates the account balance.
Args:
balance (float): The initial savings account balance.
interest_rate (float): The APR interest rate for the savings account.
months (int): The length of months to determine the amount of interest.
Returns:
float: The updated savings account balance after adding the interest earned.
float: The interest earned.
"""
# Create an instance of the `Account` class and pass in the balance and interest parameters.
account = Account(balance, 0)
# Calculate interest earned
interest_earned = balance * (interest_rate / 100) * (months / 12)
# Update the savings account balance by adding the interest earned
updated_balance = balance + interest_earned
# Pass the updated_balance to the set balance method using the instance of the SavingsAccount class.
account.set_balance(updated_balance)
# Pass the interest_earned to the set interest method using the instance of the SavingsAccount class.
account.set_interest(interest_earned)
# Return the updated balance and interest earned.
return updated_balance, interest_earned