Answered step by step
Verified Expert Solution
Question
1 Approved Answer
problem2.py contents: # INSERT ALL FUNCTION IMPLEMENTATIONS HERE # Document all functions if __name__ == __main__: print(Running the problem2 module (Bank Transactions problem)) cdict =
problem2.py contents:
# INSERT ALL FUNCTION IMPLEMENTATIONS HERE # Document all functions if __name__ == "__main__": print("Running the problem2 module (Bank Transactions problem)") cdict = customer_dictionary("balance.dat") update_customer_dictionary(cdict, "transactions.dat") new_balance_files(cdict, "transsummary.dat", "newbalance.dat") print("Updated bank balance data appears in the files transsummary.dat and newbalance.dat") print("Goodbye!")
balance.dat content:
139-28-4313 115 1056.30 706-02-6945 135 -99.06 595-74-5767 143 4289.07 972-87-1379 155 3300.26 814-50-7178 162 3571.94 632-72-6766 182 3516.77 699-77-2796 191 2565.29 814-77-4491 192 3347.81 265-40-8305 208 1446.72 940-32-8944 211 4153.07 400-19-8435 214 2501.14 794-00-0659 219 3356.98 909-38-6694 220 4496.73 495-33-4989 229 2348.31 353-78-2979 238 3960.09 169-57-3539 249 3927.39 713-79-2241 264 4938.17 016-92-4542 266 3436.31 302-52-0390 271 -89.25 050-44-5987 276 27899.48 430-00-7434 282 2155.40 935-88-9835 300 4690.44 008-41-1683 301 4120.56 262-24-2379 314 2977.82 059-96-0121 332 1164.89 541-30-5692 341 2549.50 246-75-8770 356 2389.04 484-86-7987 361 4031.13 921-96-7973 376 3684.93 602-90-2297 379 2318.76 881-80-3386 380 3622.22 645-86-7907 395 10640.25 887-60-6792 415 1835.59 973-40-7961 431 3540.63 024-13-2629 439 2754.91 992-07-5363 447 410.49 845-40-4968 466 2906.13 526-11-5286 482 2624.67 340-25-3417 502 2658.43 021-66-6171 515 2981.30 236-87-3487 522 37352.53 918-00-7767 532 10376.87 276-69-3568 546 2141.17 549-07-8738 554 -166.40 283-86-4227 573 1262.31
transactions.dat content:
380 2932.48 192 -830.84 379 2338.82 249 3444.99 466 -88.33 466 2702.32 502 -414.31 554 881.21 466 -573.21 466 -723.22 380 -139.22 314 2234.20 356 3282.70 376 2054.66 522 -22.77 482 -56.62 220 -395.45 314 2307.58 266 -510.36 482 3234.38 115 -754.64 135 1388.79 447 661.51 502 -965.05 192 -757.10 155 3999.69 249 -877.12 191 -362.88 573 341.18 431 -705.14 466 3681.81 208 -960.55 192 -36.32 229 -149.29 238 -981.39 466 -245.48 380 -958.72 532 -175.80 143 3684.72 502 2865.84 415 1161.71 282 3512.32 238 -353.76 573 1601.08 300 3545.13 300 3133.61 282 -357.51 502 -133.77 143 2072.37 466 -469.61 482 -302.51 515 2623.84 502 2356.46 356 3313.33 482 -404.72 502 -161.13 211 -804.57 182 2879.25 192 2695.03 532 -133.06 515 2128.98 271 621.07 264 2852.28 135 738.48 522 2637.24 208 -227.66 276 2178.52 380 3662.00 300 2452.39 238 3129.04 332 1200.30 264 3288.57 395 -401.19 271 1636.25 219 -414.79 276 3599.42 155 3400.67 229 2843.24 219 -811.59 115 243.11 447 948.10 395 2463.39 282 2390.41 573 -274.90 276 -900.58 264 -637.58 532 -524.61 219 2828.58 214 3210.39 208 934.60 182 -871.02 264 -950.94 162 -825.38 395 2855.23 220 2269.58 447 42.21 395 -371.09 341 -439.77 341 -643.55 379 -756.21 380 2439.77 532 -703.29 214 3220.67 208 -213.59 431 -402.45 532 -773.59 264 -578.02 264 -291.76 135 -484.24 395 3329.05 482 -871.03 466 3143.38 314 -125.18 482 3199.74 546 3260.36 219 -20.82 155 2492.74 115 1809.94 573 -507.23 522 -261.24 155 3310.54 502 -75.71 554 895.36 191 2112.17 380 -306.48 249 -87.82 431 -421.37 162 -937.98 135 578.81 515 2236.59 220 -404.63 282 2595.25 431 -793.14 192 -582.64 301 2462.46Problem 2 [25 points Bank Transactions. For this problem, you will write a program to do some basic file processing to carry out some banking transactions for the customers of a bank. Assume for our purposes that each customer has exactly one account at the bank. The bank maintains two files of data. One file contains account balance information for each customer of the bank. Each line of this file contains three data items: A customer's social security number (SSN), the bank account number, and the balance at the end of the previous business period (this might be a month, a week, or a day, but the actual length of the business period is not relevant for our purposes). The SSN is a string of digits in the usual format xxx-XX-XXXX, the bank account number is simply a three digit number (unique to each customer), and the balance is a floating point value. The second file contains all the bank transactions that have taken place in the current business period for all the customers at the bank. Each line of this file contains just two data items: a bank account number and the dollar amount of the transaction. If the transaction is a deposit, it is indicated as a positive value and if it is a payment (withdrawal), it is indicated as a negative value. A customer's bank account number may appear several times in the file (if they had several transactions during the business period) or may not appear at all (if they did not carry out any transactions at the bank during the business period). A transaction is simply recorded at the time that it takes place, hence the account numbers may appear in any order in the file and all the transactions for a particular account may not appear together (that is, on consecutive lines) in the file. The goal is to update each customer's bank balance information by taking into account all transactions (deposits as well as withdrawals) that have taken place in the current business period. If the resulting account balance is greater than $3000, a 2% interest (on the new account balance) is added on. If the resulting account balance is less than $100, a $10 penalty is applied to the account. Your program must create two files. One file should contain transaction summaries for all the customers of the bank. It should contain, for each customer, their account number, SSN, the old balance, total of all deposits made, total of all withdrawals made, the interest amount added, the penalty added, and the final new balance. The second file is the file containing the new account balance information the bank will eventually replace the old account balance file with this one). Each line of this file should contain the customer's SSN, bank account number, and the new balance at the end of the current business period. All of the data in the output files should be formatted nicely. In particular, the bank account number and SSN should be printed left-justified in appropriately chosen field widths. All dollar amounts should be printed right-justified, with a precision of 2, in appropriately chosen field widths. For the purposes of formatting, you may assume that bank balances are always below $100,000. The columns in the output file should be given appropriate headings as well (see sample files below). The above task will be accomplished by using a dictionary to keep track of a customer's transactions for the current business period, as specified in the following three functions: 1. Implement a function called customer_dictionary with a single parameter balfilename, the name of the file containing current account balance information for the customers of the bank in the format described above The function should open balfilename for reading. It should then create a dictionary with key:value pairs in which the key is the bank account number of a customer, and the value associated with a key is a list con- taining the SSN and the account balance for that customer. The function must return the dictionary. Remember to close the file prior to the return statement. 2. Implement a function called update customer_dictionary with two parameters. The first parameter, cdictionary, is the customer dictionary described above. The second parameter, transfilename, is the name of the file containing all the transactions for all the customers at the bank in the format described above This function should open transfilename for reading, and then update the cdictionary to include all the deposits and withdrawals for each customer. Recall that the value associated with each customer is a list. Hence, the deposits and the withdrawals for a customer can be recorded as additional entries in the list. Remember to close the file after it has been read completely. 3. Implement a function called new_balance files to create the two output files described above. This function has three parameters: The first parameter, cdictionary, is the customer dictionary described above. The second parameter, summfilename, is the name of the file containing the transaction summaries for the customers of the bank. The third parameter, newbalfilename, is the name of the file containing the new account balance information for all the customers. As noted above, the output files created by this function should be neatly formatted. An example is provided below. Consider the following example of the file containing account balance information: 100 300 123-45-6789 345-23-1782 672-39-1929 819-00-7810 700 348.17 3029.25 1800.87 -50.25 900 Suppose the file containing transactions data is the following file: 900 150.25 100 525.72 100 -150.75 300 -500.00 100 -27.38 300 -550.00 900 -120.00 300 2400.00 300 - 300.00 Then the output file containing transaction summaries should look like this: ACCOUNT# SSN PREV BAL DEPOSITS WITHDRAWALS INTEREST PENALTY NEW BAL 100 300 700 900 123-45-6789 345-23-1782 672-39-1929 819-00-7810 348.17 3029.25 1800.87 -50.25 525.72 2400.00 0.00 150.25 178.13 1350.00 0.00 120.00 0.00 81.58 0.00 0.00 0.00 0.00 0.00 10.00 695.76 4160.83 1800.97 -30.00 The output file containing the new account balance information should look like this: 123-45-6789 345-23-1782 672-39-1929 819-00-7810 100 300 700 900 695.76 4160.83 1800.97 -30.00 Download the following files from the Sakai site for this assignment: problem2.py, and the sample data files balance. dat and transactions.dat. Problem 2 [25 points Bank Transactions. For this problem, you will write a program to do some basic file processing to carry out some banking transactions for the customers of a bank. Assume for our purposes that each customer has exactly one account at the bank. The bank maintains two files of data. One file contains account balance information for each customer of the bank. Each line of this file contains three data items: A customer's social security number (SSN), the bank account number, and the balance at the end of the previous business period (this might be a month, a week, or a day, but the actual length of the business period is not relevant for our purposes). The SSN is a string of digits in the usual format xxx-XX-XXXX, the bank account number is simply a three digit number (unique to each customer), and the balance is a floating point value. The second file contains all the bank transactions that have taken place in the current business period for all the customers at the bank. Each line of this file contains just two data items: a bank account number and the dollar amount of the transaction. If the transaction is a deposit, it is indicated as a positive value and if it is a payment (withdrawal), it is indicated as a negative value. A customer's bank account number may appear several times in the file (if they had several transactions during the business period) or may not appear at all (if they did not carry out any transactions at the bank during the business period). A transaction is simply recorded at the time that it takes place, hence the account numbers may appear in any order in the file and all the transactions for a particular account may not appear together (that is, on consecutive lines) in the file. The goal is to update each customer's bank balance information by taking into account all transactions (deposits as well as withdrawals) that have taken place in the current business period. If the resulting account balance is greater than $3000, a 2% interest (on the new account balance) is added on. If the resulting account balance is less than $100, a $10 penalty is applied to the account. Your program must create two files. One file should contain transaction summaries for all the customers of the bank. It should contain, for each customer, their account number, SSN, the old balance, total of all deposits made, total of all withdrawals made, the interest amount added, the penalty added, and the final new balance. The second file is the file containing the new account balance information the bank will eventually replace the old account balance file with this one). Each line of this file should contain the customer's SSN, bank account number, and the new balance at the end of the current business period. All of the data in the output files should be formatted nicely. In particular, the bank account number and SSN should be printed left-justified in appropriately chosen field widths. All dollar amounts should be printed right-justified, with a precision of 2, in appropriately chosen field widths. For the purposes of formatting, you may assume that bank balances are always below $100,000. The columns in the output file should be given appropriate headings as well (see sample files below). The above task will be accomplished by using a dictionary to keep track of a customer's transactions for the current business period, as specified in the following three functions: 1. Implement a function called customer_dictionary with a single parameter balfilename, the name of the file containing current account balance information for the customers of the bank in the format described above The function should open balfilename for reading. It should then create a dictionary with key:value pairs in which the key is the bank account number of a customer, and the value associated with a key is a list con- taining the SSN and the account balance for that customer. The function must return the dictionary. Remember to close the file prior to the return statement. 2. Implement a function called update customer_dictionary with two parameters. The first parameter, cdictionary, is the customer dictionary described above. The second parameter, transfilename, is the name of the file containing all the transactions for all the customers at the bank in the format described above This function should open transfilename for reading, and then update the cdictionary to include all the deposits and withdrawals for each customer. Recall that the value associated with each customer is a list. Hence, the deposits and the withdrawals for a customer can be recorded as additional entries in the list. Remember to close the file after it has been read completely. 3. Implement a function called new_balance files to create the two output files described above. This function has three parameters: The first parameter, cdictionary, is the customer dictionary described above. The second parameter, summfilename, is the name of the file containing the transaction summaries for the customers of the bank. The third parameter, newbalfilename, is the name of the file containing the new account balance information for all the customers. As noted above, the output files created by this function should be neatly formatted. An example is provided below. Consider the following example of the file containing account balance information: 100 300 123-45-6789 345-23-1782 672-39-1929 819-00-7810 700 348.17 3029.25 1800.87 -50.25 900 Suppose the file containing transactions data is the following file: 900 150.25 100 525.72 100 -150.75 300 -500.00 100 -27.38 300 -550.00 900 -120.00 300 2400.00 300 - 300.00 Then the output file containing transaction summaries should look like this: ACCOUNT# SSN PREV BAL DEPOSITS WITHDRAWALS INTEREST PENALTY NEW BAL 100 300 700 900 123-45-6789 345-23-1782 672-39-1929 819-00-7810 348.17 3029.25 1800.87 -50.25 525.72 2400.00 0.00 150.25 178.13 1350.00 0.00 120.00 0.00 81.58 0.00 0.00 0.00 0.00 0.00 10.00 695.76 4160.83 1800.97 -30.00 The output file containing the new account balance information should look like this: 123-45-6789 345-23-1782 672-39-1929 819-00-7810 100 300 700 900 695.76 4160.83 1800.97 -30.00 Download the following files from the Sakai site for this assignment: problem2.py, and the sample data files balance. dat and transactions.dat
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started