subject

5. 6. final challengefor your final challenge in this unit, you will load two files. the first file f1 will have information about some accounts. it will be pipe-delimited and have one record per line, with these fields: account number | pin code | balancethe second file f2 will contain instructions: one on each line. the instructions will look like this: command | amount | account number | pin codecommand will be either add or sub. if the command is add, you will add amount to the balance in the account files f1. if the command is sub, you will subtract. however, there are a number of reasons for which you may need to reject the transaction. if you are asked to subtract an amount that would put the account below zero or if the pin code you are provided does not match the pin code in the account record, the transaction is ignored. account transactionsgiven pipe-delimited files f1 and f2 where f1 contains accounts with fields account num|pin|balance and f2 contains transaction instructions command|amount|account num|pin, execute the transactions, storing the results back in f1.the command field will be add or sub indicating addition or subtraction from the account. transactions which do not provide the correct pin code or attempt to put the account below zero should be ignored. check it! last run on 12/9/2017, 7: 34: 34 pm program outputyour program output did not match the expected output. your output: 1000|1234|1.0 1020||0.0 3000|3344|1000.0 2020|1234|9.0expected output: 1000|1234|11000 1020||0 3000|3344|0 2020|1234|# get the filepath from the command lineimport sysf1= sys. argv[1]f2= sys. argv[2]# your code goes here#empty dictionary for holding balance data read from f1balance_dict = ()#iterate through each line in f1 and store in the balance_dict with account number as the key#handle the case in which the file doesn't or the path is wronglines1 = []lines2 = []with open(f1) as fh: lines1 = fh. readlines()with open(f2) as fh: lines2 = fh. readlines()accounts = {}account_list = []for line in lines1: (account, pin, balance) = line. split("|")accounts[account] = [pin, float(balance)]account_list. append(account)commands = []for line in lines2: (command, amount, account, pin) = line. split("|") if account in accounts: if command == "add" and accounts[account][0] == pin: accounts[account][1] += amountelif command == "sub" and accounts[account][0] == pin and (accounts[account][1] - amount > = 0): accounts[account][1] -= amountwith open(f1, "w") as fw: for account in account_list: pin = accounts[account][0]amount = str(accounts[account][1])fw. write(account + "|" + pin + "|" + amount + "\n")

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:30, sunshinekisses
After you clean an engine with hot water spray, it seems to stall; when it doesn't stall, it's idling noisily. technician a says to check for loose bolts on the flex plate near the torque converter. technician b says to wipe down the spark plug wires and the distributor cap. who is correct? a. technician a b. both technicians a and b c. technician b
Answers: 1
image
Computers and Technology, 23.06.2019 19:40, Latoyajenjins1789
Use a physical stopwatch to record the length of time it takes to run the program. calculate the difference obtained by calls to the method system. currenttimemillis() just before the start of the algorithm and just after the end of the algorithm. calculate the difference obtained by calls to the method system. currenttimemillis() at the start of the program and at the end of the program so that the elapsed time includes the display of the result. use the value returned by the method system. currenttimemillis() just after the end of the algorithm as the elapsed time.
Answers: 3
image
Computers and Technology, 24.06.2019 11:00, abolton04
In three to five sentences, describe how you can organize written information logically and sequentially
Answers: 1
image
Computers and Technology, 25.06.2019 09:50, tatilynnsoto17
Part a: data processing given a data file, find the max, min, and average values of columns. also, create an addition column that is based on the other columns. there will be no error checking required for this lab. you are provided with a data file named (surprise! ) data. txt. data is arranged in columns where each item of data is twelve columns wide (so it is easy to extract data items using slicing): name height(m) weight(kg) joe 1.82 72.57 mary 1.60 63.50 dion 1.90 90.71 kayla 1.72 66.31 jose 1.78 70.23 sofia 1.63 65.12 erik 1.98 92.21 sara 1.57 65.77 your task is read the file data. txt and calculate the max, min, and average of the height and weight columns and to add an additional column that has the bmi calculated based on each height and weight. your output will look like this (and needs to be formatted like this). to match the testing on mimir here is the format string: "{: < 12s}{: < 12.2f}{: < 12.2f}{: < 12.2f}"
Answers: 3
You know the right answer?
5. 6. final challengefor your final challenge in this unit, you will load two files. the first file...

Questions in other subjects:

Konu
Business, 24.09.2020 01:01
Konu
Mathematics, 24.09.2020 01:01
Konu
History, 24.09.2020 01:01