Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Speak plainly and briefly, and avoid jargon.

Answered: 1 week ago