Question: Using Python 3+ Develop a class BankAccount with six methods: __init__ - constructor, is able to construct a bank account with a given balance, or,

Using Python 3+

Develop a class BankAccount with six methods:

__init__ - constructor, is able to construct a bank account with a given balance, or, if no balance is specified the balance defaults to 0. (see runs below)

__repr__ - converts BankAccount to a str for display, see runs below.

set which takes a numeric amount as a parameter and sets the account balance to that parameter

withdraw - which takes a numeric amount as a parameter and withdraws the amount specified by the parameter from the balance on the account

deposit - which takes a numeric amount as a parameter and deposits the amount specified by the parameter from the balance on the account

balance - which takes no parameters and returns the current balance on the account

The following output must be correct for the doc test to receive 0 failed examples:

##### BankAccount ######

>>> b = BankAccount(100) >>> b BankAccount(100) >>> b = BankAccount() >>> b BankAccount(0) >>> [b] # check that str is returned, not printed [BankAccount(0)]

# methods

>>> b.deposit(50.25) >>> b BankAccount(50.25) >>> b.withdraw(17.50) >>> b BankAccount(32.75) >>> b.balance() 32.75 >>> b.balance()==32.75 # check balance is returned, not printed True

Write a function processAccount() that takes one argument, the name of a file The first line of the file is a number, which indicates the initial balance for a bank account. The remaining lines consist of a single character followed by a space followed by a number. The character will be one of 'd', 'D', 'w', or 'W', indicating that the amount that follows is either a withdrawal ('w' or 'W') or a deposit ('d' or 'D'). The function will create a new BankAccount object and then process each line of the file by calling the appropriate method of the BankAccount object. As it processes each line, it will print the information about the transaction being processed. The first line will be a call to the set() method and the remaining lines will be calls either to the deposit() or withdraw() method. Once the file has been processed, the function will return the BankAccount object.

The following output must be correct for the doc test to receive 0 failed examples:

###### processAccount ######

# able to manipulate accounts

>>> processAccount('acct1.txt') BankAccount(605.5500000000001) >>> b = processAccount('acct1.txt') >>> b BankAccount(605.5500000000001) >>> b.balance() 605.5500000000001

>>> b = processAccount('acct2.txt') >>> b BankAccount(46.94) >>> b.balance() 46.94

>>> b = processAccount('acct3.txt') >>> b BankAccount(216.64) >>> b.balance() 216.64

'''now, run some checks on the code in the file, make sure it is using a BankAccount object and methods and not doing + and - also make sure there is a return statement and no print'''

>>> import inspect >>> >>> >>> code = inspect.getsource(processAccount) >>> 'BankAccount' in code True >>> '.deposit' in code True >>> '.withdraw' in code True >>> '+' in code or '-' in code False >>> 'return' in code True

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!