Ask 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, 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.

+1
Answers (1)
  1. 17 January, 03:27
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers