[Solved]Python Program Program Process Individual Transactions Customer Accounts Case Weren T Sure Q37029404
Python Program:
-
- Your program will process the individual transactions againstcustomer accounts (in case you weren’t sure…there are multiplecustomers, but they only have one account each).
- Your program should ask for the path to the files containingthe customer and transaction data. The instructor will use testfiles that will not be made available to the student.
- You will produce an updated customer master file that containsthe new beginning balance, which will be the end balance after youare finished processing all transactions.
- Beginning Balance
- Less Checks
- Plus Deposits
- Plus Interest earned
- Ending Balance – This will become the new value ofthe beginning balance.
- The interest paid is .25% of the ending balance. Bonus forcomputing it as average daily balance in theaccount (note the bolded text).
- At the end of the run produce an error reportfile that contains all of the errant transactions found duringprocessing. This output should contain information to identify thetransaction and a list of the problems found with the item.DUPLICATED CHECK NUMBERS AND BOGUS ACCOUNT NUMBERS AREDEFINITE ERRORS!!
- This program should be built to handle millions oftransactions, so use algorithms that are maximized for largenumbers of transactions (i.e. shell sorts).
- You will be graded based on successful completion of theassignment, correctness of output, and quality of your codingpractice (naming, comments, proper use of structure, coupling,cohesion, etc.)
Here’s the code I have so far:
# Declarations
masterfile_in = ”
transfile_in = ”
updatedfile_out = ”
masterRecord = []
transRecord = []
# Constants and Switches – Kill both of these.
# END_NUM = 9999 # Very old and limiting way to do this… so let’sKILL it.
# areBothAtEnd = False # Going to use a Boolean, because I can andit’s easier to read
# Modern Problems Require Modern Solutions
# IMROVED RECORD COMPARISON ITEMS
current_mstr = str()
current_trans = str()
eof_mstr = False
eof_trans = False
trans_count = 0
trans_total = 0
def readMaster():
“””
This function reads the next record from the Master file. Alsochecks to see if at the end of the file.
This function will load a record, and then set values forcomparison and accumulation.
:return: *Really just sets the module level variables indicatingthe end.
“””
global masterRecord
# Improved method
global eof_mstr
global current_mstr
masterRecord =masterfile_in.readline().rstrip(‘n’).split(‘,’)
if masterRecord[0] == ”:
# Reading into a list will always produce at least one element, so[0] is OK.
# masterRecord[0] = END_NUM #kill this weird method
eof_mstr = True
else:
# Set a standard current record value. This eleminates issue ofvalues being in various element locations.
current_mstr = masterRecord[0]
def readTrans():
“””
This function reads the next record from the Transaction file. Alsochecks to see if at the end of the file.
This function will load a record, and then set values forcomparison and accumulation.
:return: *Really ust sets the module level variables indicating theend.
“””
global transRecord
global credit_count
global credit_total
# Improved method
global eof_trans
global current_trans
transRecord = transfile_in.readline().rstrip(‘n’).split(‘,’)
if transRecord[0] == ”:
# Reading into a list will always produce at least one element, so[0] is OK.
# transRecord[0] = END_NUM # kill this old timie method
eof_trans = True
else:
# Set a standard current record value. This eleminates issue ofvalues being in various element locations.
# Do all the detail work here so rest of program doesn’t know thedifference
current_trans = transRecord[5]
def houseKeeping():
“””
This function performs the initial set up for the processingoperation. File handles are opened.
:return:
“””
global masterfile_in
global transfile_in
global updatedfile_out
masterfile_in = open(‘CustFile.txt’, ‘r’)
transfile_in = open(‘CustTrans.txt’, ‘r’)
updatedfile_out = open(‘ScottJrUPDAMSTR.txt’, ‘w’)
def updateRecords():
“””
This is the central transform operation of the program. We processthe transactions against
the master records and calculate a new balance.
:return:
“””
# Remember that if we aren’t chnaging a module level variable, wedon’t need to list it as global here.
# We need to control our loop inside this function. Also means wecan do our lead reads here as well
global trans_count
global trans_total
global credit_count
global credit_total
readMaster()
readTrans()
while (eof_mstr == False) and (eof_trans == False):
# Using a standard comparison variable… so no out of rangeissue
if current_mstr == current_trans:
# Process this transaction record and get next trans
# Now that we have a better understanding of lists, let’s use thatpower. Ask me in class why
# we can accumulate right to the list element itself.
if transRecord[3] == ‘T’:
trans_count = trans_count + 1
trans_total = round(trans_total,2) + float(transRecord[4])
else:
credit_count = credit_count + 1
credit_total = round(credit_total,2) + float(transRecord[4])
# Get next Transaction
readTrans()
else:
if current_mstr < current_trans:
# We are into the next customers transactions
writeUpdate()
trans_count = 0
trans_total = 0
credit_count = 0
credit_count = 0
# Get the next Master
readMaster()
else:
# We would normally output this to an error file…but you canfigure that out for yourself
errorOutput()
readTrans()
# We’re done, so write out the last customer’s data
writeUpdate()
# If we have more master records, we can just write them to theupdated master file. If we have left over transactions
# at this point…they’re all bad and I call shennanigans.
def writeUpdate():
“””
This function handles writing the updated customer record tofile.
:return:
“””
outputRec = str(masterRecord[0]) + ‘vendor Name’ +str(masterRecord[1]) + ‘n’ + str(trans_total) + ‘n’ +str(trans_count) + ‘n’ + str(credit_total) + ‘n’ +str(credit_count) + ‘n’
updatedfile_out.write(outputRec)
def errorOutput():
errorfile_out = open(‘ScottJrERR.txt’, ‘w’)
outputRec = str(masterRecord[0]) + ‘,’ + str(masterRecord[1]) + ‘,’+ ‘This is a bad transaction’
errorfile_out.write(outputRec)
def finishUp():
“””
Wraps up processing and closes all open resources.
:return:
“””
masterfile_in.close()
transfile_in.close()
updatedfile_out.close()
def Main():
“””
Mainline logic for this program
:return:
“””
houseKeeping()
updateRecords()
finishUp()
if __name__ == ‘__main__’:
Main()
Expert Answer
Answer to Python Program: Your program will process the individual transactions against customer accounts (in case you weren’t s… . . .
OR

