In: Computer Science
IN PYTHON:
write a new subclass hiAccount that allows you to earn interest at the rate of .01% per SECOND.
Write a new method called checkBalance for hiAccount that computes hiAccount's value, accounting for the growth of your hiAccount between when the time when the deposit was made and when you invoke checkBalance.
using following code:
class Account:
"""A bank account that has a non-negative balance."""
def __init__(self, account_holder):
"""Every Account is described using the name of the account holder,
which is a string."""
self.balance = 0
self.holder = account_holder
def deposit(self, amount):
"""Increase the account balance by amount and return the new
balance."""
self.balance = self.balance + amount
return self.balance
def withdraw(self, amount):
"""Decrease the account balance by amount and return the new
balance."""
if amount > self.balance:
return 'Insufficient funds'
self.balance = self.balance - amount
return self.balance
code:
Account.py
class Account:
"""A bank account that has a non-negative
balance."""
def __init__(self, account_holder):
"""Every Account is described using
the name of the account holder, which is a string."""
self.balance = 0
self.holder = account_holder
def deposit(self, amount):
"""Increase the account balance by
amount and return the new balance."""
self.balance = self.balance +
amount
return self.balance
def withdraw(self, amount):
"""Decrease the account balance by
amount and return the new balance."""
if amount > self.balance:
return
'Insufficient funds'
self.balance = self.balance -
amount
return self.balance
hiAccount.py:
import time
import math
from Account import Account
class hiAccount(Account):
def __init__(self, account_holder):
Account.__init__(self,account_holder)
self.currentime=time.time()
def checkBalance(self):
time_now=time.time()
self.balance=(self.balance)*(1+0.01/100)**math.floor((time_now-self.currentime))
self.currentime=time_now
return self.balance
hiAccountHolder1=hiAccount('Adam')
hiAccountHolder1.deposit(100)
hiAccountHolder1.currentime=time.time()
print("Hi "+hiAccountHolder1.holder+" 100 bucks is deposited in
your account:")
print("Updated balance is")
print(hiAccountHolder1.checkBalance())
time.sleep(10)
print("After 10 seconds, updated balance is:")
print(hiAccountHolder1.checkBalance())
Reference for indendation:
Sample i/o:
Explanation:
To demonstrate the compouding for every second, I have used
sleep(10). The check balance method, keeps track of the balance
updated time and the present time and calculates a compound
interest.
Sample i/o is presented for better understanding. The program is
run in python 3.7.
**Please upvote if you like the answer