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
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.
+ 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.