Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions count_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Write a function that should count word occurance in file.
Define function 'countWord' which will accept two arguments, filepath and word to find inside file.
You can create your own file or you can use given testfile.txt inside files directory.
Calculate word occurance. Function should return count.
Function should pass all test cases.
Instructions:

Program should be written in file count_word.py
Function name should be countWord.
Input
File = Learning from machine, machine learning.

Type: File path and string
Value: Word = learning
Expected Output
Type: Integer
Value: 2
"""
def countWord(filename,word):
count = 0
f = open(filename,'r')
for line in f:
if word in line:
count+=1
f.close()
return count
Binary file added count_word.pyc
Binary file not shown.
Binary file added tests/__init__.pyc
Binary file not shown.
Binary file added tests/test_countWord.pyc
Binary file not shown.