Question: Python 3 1 .Modify the deposit and withdraw methods in the below activecode to append the amount to the transaction list (for withdraw, append the

Python 3

1.Modify the deposit and withdraw methods in the below activecode to append the amount to the transaction list (for withdraw, append the negative of the amount).

2.Modify the statement method (between the two existing print statements) to iterate over the list of transactions, displaying its amount and the balance after this transaction posts.

class Account:

'''Account class for representing and manipulating bank accounts'''

def __init__(self):

'''Create a new account with zero balance'''

self.__balance = 0.00

self.__transactions = []

self.__start = 0.00

def getBalance(self):

return self.__balance

def deposit(self, amount):

'''increase balance by a positive amount'''

if amount >= 0:

self.__balance += amount

def withdraw(self, amount):

'''reduce balance by amount but do not an allow overdraft'''

if self.__balance >= amount:

self.__balance -= amount

def __str__(self):

return "${:,.2f}".format(self.__balance)

def statement(self):

'''list the transactions with the running balance'''

bal = self.__start

print('starting balance ${:>8,.2f}'.format(bal))

print('ending balance ${:>8,.2f}'.format(self.__balance))

p = Account()

p.deposit(150)

p.withdraw(30)

p.withdraw(20)

p.statement()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!