Question
5. 3. Challenge: Fixed Length Records Fixed Length Records You will be passed the filename P, firstname F, lastname L, and a new birthday B.
5. 3. Challenge: Fixed Length Records Fixed Length Records You will be passed the filename P, firstname F, lastname L, and a new birthday B. Load the fixed length record file in P, search for F,L in the first and change birthday to B. Hint: Each record is at a fixed length of 16. Then save the file.
I am getting the following results:
Program Output
Your program output did not match the expected output. Your output: Adam Smith 11111985 Expected output: Adam Smith 11111985Theodore Anderson 03201990Monty Biscuit-Barrel 10181980Adam Smithers 00000000Ruthy Anderson 06062010
My code so far is as follows:
# Get the filepath from the command line import sys P= sys.argv[1] F= sys.argv[2] L= sys.argv[3] B= sys.argv[4]
# Your Code Goes Here record = [] recordList = [] # Get the file file = open(P, 'r') data = file.read() file.close()
# read all the records while len(data) > 0: record.append(data[0:16]) record.append(data[16:32]) record.append(data[32:40]) recordList.append(record) data = data[40:]
# Find and replace output = '' for i in range(0, len(recordList)): thisRecord = recordList[i] if thisRecord[0].strip() == F: if thisRecord[1].strip() == L: thisRecord[2] = B
# print out all of our records output += thisRecord[0] + thisRecord[1] + thisRecord[2]
file = open(P, 'w') file.write(output) file.close()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started