Question: Please help me fix this code: # Prompt user for input and output file names file 1 _ name = input ( Enter the

Please help me fix this code:
# Prompt user for input and output file names
file1_name = input("Enter the name of input file without .txt extension: ")
file2_name = input("Enter the name of output file without .txt extension: ")
# Open input and output files
with open(file1_name +".txt","r") as file1, open(file2_name +".txt","w") as file2:
# Write headers to output file
file2.write('{0:<20}{1:<10}{2:<10}{3:<10}{4:<10}{5:<15}{6:<15}{7:<10}
'.format("Name.","ID.","(Test1)","(Test2)","(HW)","(Project)","TotalScore","Grade"))
# Process each line in the input file
for line_number, line in enumerate(file1.readlines()):
# Split line data by colon delimiter
data = line.strip().split(':')
# Extract relevant information
name = data[0].strip()
student_id = data[1].strip()
test1= int(data[2].strip())
test2= int(data[3].strip())
hw = int(data[4].strip())
project = int(data[5].strip())
# Calculate total score
total_score =(0.2* test1)+(0.2* test2)+(0.4* hw)+(0.2* project)
# Determine grade
grade ='A' if total_score >=90 else ('B' if total_score >=80 else ('C' if total_score >=70 else ('D' if total_score >=60 else 'F')))
# Write data to output file
file2.write('{0:<20}{1:<10}{2:<10}{3:<10}{4:<10}{5:<15}{6:<15}{7:<10}
'.format(name, student_id, test1, test2, hw, project, int(total_score), grade))
print("Process was done successfully")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!