lab3-extra

wc(filename)

Write a function wc(filename) that returns the number of words in file filename. The name wc stands for Word Count. To split a string s into words, use s.split() for this exercise (i.e. the behaviour of the split() method is used here to define what a word is).

Example 1: For a file data.txt with content:

One Two

a function call wc('data.txt') should return 2.

Example 2: For a file data.txt with content:

One Two
Three Four Five

a function call wc('data.txt') should return 5.

You can test your function on the Alice in Wonderland book and should expect that this has more than 10,000 words.

(If you use Linux or OSX, you can download a file offered at a URL using wget URL from the a terminal. For this example, try wget https://www.gutenberg.org/files/19033/19033.txt).


Please include the extra tasks in your file lab3.py and submit as lab3 assignment.

Back to lab3.

End of lab3-extra.