Ask Question
13 February, 16:48

A common utility on UniX/Linux systems is a small program called ''wc." This program analyzes a file to determine the number of lines, words, and characters contained therein.

Write your own version of wc. The program should accept a file name as input and then print three numbers showing the count of lines, words, and characters in the file.

+5
Answers (1)
  1. 13 February, 20:11
    0
    import string

    print 'Enter filename'

    filename = raw_input ()

    filedata = open (filename, 'r'). read ()

    print 'Lines:', len (filedata. splitlines ())

    print 'Words:', len (string. split (filedata))

    print 'Chars:', len (filedata)

    Explanation:

    Python programming language is a language that was designed by Guido Van Rossum in the year 1991 and works on operating systems such as Linux, Windows Vista and many more OS or operating system.

    In this question we are asked to write a program version that should accept a file name as input and "then print three numbers showing the count of lines, words, and characters in the file."

    Hence, in this question always remember to put your code file as well as your example. txt file in the same folder.

    import string

    print 'Enter filename'

    filename = raw_input ()

    filedata = open (filename, 'r'). read ()

    print 'Lines:', len (filedata. splitlines ())

    print 'Words:', len (string. split (filedata))

    print 'Chars:', len (filedata)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “A common utility on UniX/Linux systems is a small program called ''wc." This program analyzes a file to determine the number of lines, ...” 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