You are on page 1of 1

run1_file = open("run1.

txt", "r")
run2_file = open("run2.txt", "r")

sorted_file = open("sorted.txt", "w")

run1_line = run1_file.readline()
run2_line = run2_file.readline()

while run1_line and run2_line:


# Convert the strings to integers
run1_num = int(run1_line.strip())
run2_num = int(run2_line.strip())

# Compare the first elements of the two runs


if run1_num <= run2_num:
# Add the smaller element to the sorted list
sorted_file.write(str(run1_num) + "\n")
run1_line = run1_file.readline()
else:
# Add the smaller element to the sorted list
sorted_file.write(str(run2_num) + "\n")
run2_line = run2_file.readline()

while run1_line:
sorted_file.write(run1_line)
run1_line = run1_file.readline()

while run2_line:
sorted_file.write(run2_line)
run2_line = run2_file.readline()

run1_file.close()
run2_file.close()
sorted_file.close()

You might also like