This is one full question. Please write in Python. The starter
code mentioned is copied and pasted at the bottom below the
picture.
'''
This class represents a bank account. Exciting times!
'''
class BankAccount:
# Constructor - allows us to specify the owner,
initial balance, account
# type, and interest rate
def __init__(self, owner, balance, is_savings,
rate):
self.owner = owner
# Name of account owner
self.balance = balance
# Current
account balance
self.is_savings =
is_savings # False for checking, True for
savings
self.interest_rate = rate
# As a percentage (e.g., 1
for 1%)
acct_type = 'savings' if
self.is_savings else 'checking'
print(f'Created a new
{acct_type} account for {self.owner} with balance
${self.balance:.2f}, interest rate {self.interest_rate}%.')
# Deposits the specified amount into the
account
def deposit(self, amount):
if amount <= 0:
print('Deposit amount must be positive. No changes to
account made.')
else:
self.balance += amount
print(f"Deposited ${amount:.2f} into {self.owner}'s account,
new balance is ${self.balance:.2f}.")
# Withdraws the specified amount from the
account
def withdraw(self, amount):
if amount <= 0:
print('Withdraw amount must be positive. No changes to
account made.')
elif amount >
self.balance:
print('Withdraw amount exceeds available balance. No
changes to account made.')
else:
self.balance -= amount
print(f"Withdrew ${amount:.2f} from {self.owner}'s account,
new balance is ${self.balance:.2f}.")
# Modifies the interest rate of the account
by the specified amount, as a
# percentage
def adjust_interest_rate(self, amount):
self.interest_rate +=
amount
print(f"Changed interest rate
on {self.owner}'s account by {amount}%, new interest rate is
{self.interest_rate}%.")
# Makes one annual interest payment to the
account, based on the current
# balance and interest_rate
def pay_interest(self):
interest = self.interest_rate
/ 100 * self.balance;
self.balance +=
interest
print(f"Made interest payment
of ${interest:.2f} to {self.owner}'s account, new balance is
${self.balance:.2f}.")
# YOUR CODE BELOW THIS LINE
1. (6 points) Start by downloading and unzipping the starter code included with the assignment. Within the file bank account.py, there's a BankAccount class that represents (surprise) a bank account! Carefully read over the code. At the bottom of bank account.py, write a program that performs the actions below, by calling the various instance methods provided in BankAccount. Do not make any changes to the BankAccount class definition. • Create a new savings account for Poor College Student with an initial deposit of $0.00 and an interest rate of 0.4%. • Create a new checking account for Scrooge McDuck with an initial deposit of $75,000.00 and an interest rate of 0.01%. • Poor College Student just got paid! Deposit $1000 to Poor College Student's account. • Scrooge wants to take a fancy vacation! Withdraw $30,000 from Scrooge McDuck's ac- count. • The Fed has raised interest rates! Increase the interest rate on Poor College Student's account by 0.3%, and on Scrooge's account by 0.01% (checking accounts are very stingy with interest). • Make an annual interest payment to both accounts.
This is one full question. Please write in Python. The starter code mentioned is copied and pasted at the bottom below t
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
This is one full question. Please write in Python. The starter code mentioned is copied and pasted at the bottom below t
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!