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, 22.06.2019 22:30
What is the most popular genre of video games?
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Idon’t understand the double8 coding problem. it is java
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
What is one reason why indoor air pollution has become an increasing problem.
Answers: 1
question
Computers and Technology, 25.06.2019 02:30
What does a trademark indicate about a product? a trademark is a sign, symbol, or short phrase that indicates the of a product or service. type the correct answer in the box
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
Biology, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Geography, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
question
Mathematics, 13.09.2020 22:01
Questions on the website: 13722361