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

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:30
What important technology has done the most to allow a businesses a chance to compete with larger international companies
Answers: 1
question
Computers and Technology, 22.06.2019 08:00
Two technicians are discussing the common u-joint. technician a says its input and output speeds should be equal. technician b says that it normally has two yokes. which technician is correct?
Answers: 1
question
Computers and Technology, 22.06.2019 12:40
How do i get the most points, without any effort?
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Pl i need the answer now ! which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 1
You know the right answer?
5. 6. final challengefor your final challenge in this unit, you will load two files. the first file...
Questions
question
Spanish, 01.07.2019 10:50
question
Mathematics, 01.07.2019 10:50
Questions on the website: 13722363