Ask Question
22 March, 15:09

File Letter Counter

Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program.

+2
Answers (1)
  1. 22 March, 17:44
    0
    The solution code is written in Python.

    fileName = input ("Enter file name: ") target = input ("Enter target character: ") with open (fileName, "r") as reader: content = reader. read () print (content. count (target))

    Explanation:

    Firstly, use input () function to prompt user for a file name. (Line 1)

    Next, we use input () function again to prompt user input a target character (Line 2)

    Create a reader object and user read () method to copy entire texts from to the variable content (Line 4 - 5).

    At last we can get the number of times the specified character appears in the file using the Python string built-in method count () (Line 6)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “File Letter Counter Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers