Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
3. Question 2


Amazing! The next question is about file operations.


Write a function named count_word(file_name, word) that opens a file with its name given as the first argument and reads that file line by line. Each line contains a single word. The function returns the number of lines that contain the word given as the second argument.

Stuck? Here's a hint!

If you use a for loop like this:

for line in file_name:

Remember that each line with a word will have '\n' (the newline character) at the end.