0

Can anybody help me to do the question through python

Ask user for two files with integer numbers (one number in a row). If one of the files does not exist, print a message and finish. Find the numbers that are overlapping and write them to a new file. For example First file 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 Second file 1 7 10 13 19 23 28 31 32 44 49 68 70 79 82 86 91 94 97 100 New file 13 19 23 31 79 97

11th May 2021, 7:17 AM
Golam Haider
Golam Haider - avatar
2 Answers
+ 5
Golam Haider , before we are going to help you, please show us your attempt. put your code in playground and link it here. if you have not done a try by yourself until now, please do so, and show it here. thanks for your understanding.
11th May 2021, 2:01 PM
Lothar
Lothar - avatar
+ 5
Here are some hints to do the task: ▪︎first you have to create 2 files with the respective numbers. use a simple text editor to create the files. save them in the same directory as your code will be stored. ▪︎use a try... except... construct to open and read the files. this will prevent the program from crashing when one or both of the files could not be found. •if files could be found and opened, the codelines after open(...) will be executed. •if no error occures, the content of file 1 is read. use a for loop for this, and put each number given from the loop in a list •do the same with file 2 •if an error occures, the "except" part will be executed. an appropriate message should be shown, and no further processing be done •as the final step you have to find values that occur in both of the files. you can do this with a for loop or by using a set instead. set has an intersection() method, that returns the common elements of the 2 lists.
11th May 2021, 4:39 PM
Lothar
Lothar - avatar