Computers and Technology

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")

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 11:30, leapfroggiez
Auser is given read permission to a file stored on an ntfs-formatted volume. the file is then copied to a folder on the same ntfs-formatted volume where the user has been given full control permission for that folder. when the user logs on to the computer holding the file and accesses its new location via a drive letter, what is the user's effective permission to the file? a. read b. full control c. no access d. modify e. none of the above
Answers: 1
image
Computers and Technology, 23.06.2019 13:30, carolelai08
Stops: using the information learned in this course, explain three things you will not do when driving. a. b. c. explain why you will not do these things when driving. starts: using the information learned in this course, explain three things you will do when driving. a. b. c. explain why you will do these particular things when driving. explain one thing you will stop doing as a passenger. explain one thing you will start doing as a passenger.
Answers: 3
image
Computers and Technology, 23.06.2019 17:00, Alexaisokay1
In which of the following ways can using test-taking tips you? a. you can focus on the information that you need to study. b. you will see the answers to the test. c. you will study more. d. you will be less organized.
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, aalyssag606
This program should be a short piece of code that prints all of the positive integers from 1 to 100 as described more fully below. the program may contain multiple methods, and if using an oo language, should be contained within a single class or object. the program should be designed so that it begins execution when invoked through whichever mechanism is most common for the implementation language. â–ş print out all positive integers from 1 to 100, inclusive and in order. â–ş print messages to standard output, matching the sample output below. â–ş in the output, state whether the each integer is 'odd' or 'even' in the output. â–ş if the number is divisible by three, instead of stating that the number is odd or even, state that the number is 'divisible by three'. â–ş if the number is divisible by both two and three, instead of saying that the number is odd, even or divisible by three; state that the number is 'divisible by two and three'. â–ş design the logic of the loop to be as efficient as possible, using the minimal number of operations to perform the required logic. sample output the number '1' is odd. the number '2' is even. the number '3' is divisible by three. the number '6' is divisible by two and three.
Answers: 1
Do you know the correct answer?
5. 6. final challengefor your final challenge in this unit, you will load two files. the first file...

Questions in other subjects:

Konu
Chemistry, 20.10.2020 01:01
Konu
Mathematics, 20.10.2020 01:01
Konu
Mathematics, 20.10.2020 01:01