Codio Project File Edit Find View Tools Education Help , Node version. Project I
ID: 3909920 • Letter: C
Question
Codio Project File Edit Find View Tools Education Help , Node version. Project Index (static). Configure ? bank-transa...X 5. 6. Final ch...X 1 # Get the filepath from the command line import sys F1- sys.argvl] F2 sys.argv[2] CollapseData formats 5 6. Final challenge # Your code goes here Account Transactions Given pipe-delimited files F1 and F2 where F1 contains accounts with fields ACCOUNT NUMIPINIBALANCE and F2 contains transaction instructions COMMAND IAMOUNTIACCOUNT NUMIPIN 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 ignoredExplanation / Answer
import sys
f1 = open(sys.argv[1], "r")
f2 = open(sys.argv[2], "r")
list = []
for line in f1:
list1 = line.split("|")
for j in range(len(list1)):
list1[j] = list1[j].strip(' ')
list.append(list1)
f1.close()
for line in f2:
list1 = line.split("|")
list1[len(list1)-1] = list1[len(list1)-1].strip(' ')
list1[len(list1)-1] = list1[len(list1)-1].strip(' ')
#print(list1)
for i in range(len(list)):
#print(list[i][0] , list1[2], list1[3], list[i][1])
if list1[2] == list[i][0] and list1[3] == list[i][1]:
if list1[0] == "add":
a = int(list[i][2])
b = int(list1[1])
a = a + b
list[i][2] = str(a)
if list1[0] == "sub":
a = int(list[i][2])
b = int(list1[1])
a = a - b
if a >= 0:
list[i][2] = str(a)
f2.close()
f1 = open(sys.argv[1], "w")
for i in range(len(list)):
str1 = ""
for j in range(len(list[i])):
if j != len(list[i]) - 1:
str1 = str1 + list[i][j] + "|"
else:
str1 = str1 + list[i][j]
f1.write(str1+ " ")
f1.close()