Question: Exercise 4 : Mers Restart the kernel ts from Files Use the with open statement to create a file called numbers 1 . txt and

Exercise 4: Mers
Restart the kernel ts from Files
Use the with open statement to create a file called numbers1.txt and write the numbers \(1,10,25,75,100\). Use the with open statement to create a file called numbers \(2. t x t \) and write the numbers \(2,15,40,50,90\). Merge the two sorted lists of numbers from the two files into a new file called merged_file.txt. Finally, fead and display the content of the new file merged_file.txt Note: Ensure you handle exceptions and errors appropriately.
```
[64]: # Exercise 4: Merge Sorted Lists from Files
# Write the numbers (1,10,25,75,100) to numbers1.txt
with open('numbers1.txt','w') as file:
file.write("1
10
25
75
100
")
-[62]: # Write the numbers (2,15,40,50,90) to numbers2.txt
#Your code goes here
-[72]: # Merge sorted lists from files into merged_file.txt
with open('numbers1.txt','r') as file1, open('numbers2.txt','r') as file2, open('merged_file.txt','w') as output:
list1=[int(line.strip()) for line in file1.readlines()]
list2=[int(line.strip()) for line in file2.readlines()]
# Merge sorted lists
# Your code goes here
# Write the merged list to the output file using a for loop
# Your code goes here
```
Read and display the content of the new file merged_file.txt
[77]: \# Your code goes here
\# Read and display the content of the file
[]:
Exercise 4 : Mers Restart the kernel ts from

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 Programming Questions!