In Python, write a program that reads a text file that is provided by the user - ensure that the file exists before processing it! The file might be in a different directory, so be sure to test you logic - the user will provide the absolute path to the file if it is not in the same directory as the Python script! You should then ask the user for what string to search for in the file. Your program should then write each line that has a matching entry for the string entered by the user to a file in the current directory called "matches.txt" that should be cleared on each run of the program. You may assume that the user has permission to read the file.

OUTPUT :

CODE :
file = input('Enter file name: ')
try:
#Open file to read
f = open(file,'r')
#Open file to write
w = open('matches.txt','w')
#read string to search
s = input('Please enter string to search: ')
#Read all lines
for line in f:
#write to file
if s in line:
w.write(line)
w.flush()
w.close()
f.close()
except:
print('File not found')
In Python, write a program that reads a text file that is provided by the user...
(Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...
Write a Python program that reads text from a file, encrypts it with a Caesar Cipher, and displays the encrypted text. Do not process punctuation. Convert the original string to all lower-case before encrypting it.
In Python 3, Write a program that reads in a text file that consists of some standard English text. Your program should count the number of occurrences of each letter of the alphabet, and display each letter with its count, in the order of increasing count. What are the six most frequently used letters?
Write a Python program which prompts the user for a file name then a sentence. Display the number of characters in the sentence and save the sentence to the file name. If the file already exists, ask the user if the file should be overwritten.
Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1 0.5 2 0.5 3 0.5 4 0.5 The output should be: The averages are 2.50 and 0.5. a) Your code with comments b) A screenshot of the execution Version 3.7.2
write a python program that prompts the user for a name of a text file, opens that file for reading , and tracks the unique words in a file and counts how many times they occur in the file. Your program should output the unique words and how often they occur in alphabetical order. Negative testing for a file that does not exist and an empty file should be implemented.
Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...
Write a complete Python program with prompts for the user for the main text file (checks that it exists, and if not, output an error message and stop), for any possible flags (including none), and for any other input that this program may need from the user: split has an option of naming the smaller files head_tail list the first 10 lines (default) and the last 10 lines (default) in order of the given text file flag: -# output #...
(Count the occurrences of each keyword) Write a python program that reads in a Python source code file and counts the occurrence of each keyword in the file. Your program should prompt the user to enter the Python source code filename.
Python
3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018
3. Date Printer Write a program that reads a string from the user containing a date in the form mm/dd/yyyy. It should print the date in the format March 12, 2018