Ask Question
27 June, 16:04

Write a function called word_count that takes a single argument, a string containing the text of a single chapter, and returns the number of words in that chapter. Assume that words are separated from each other by spaces. Apply your function to compute the variable wc (defined in the cell below).

+4
Answers (1)
  1. 27 June, 19:55
    0
    Hi there! There are a number of ways to achieve the word count result given an input text. The easiest method is explained below.

    Explanation:

    A simple Python script, word_count. py, can be used to calculate the word count program. The first argument is taken as the input text string (it needs to be enclosed in quotes (" ") in the command line). This input text is then split by spaces to capture the complete words list in an array. Finally, the length of the array equals the word count.

    word_count. py

    import sys;

    text = sys. argv[1];

    words = text. split (" ");

    wc = len (words);

    print (wc);
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function called word_count that takes a single argument, a string containing the text of a single chapter, and returns the number ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers