diff --git a/count_word.py b/count_word.py index e69de29..0bc7103 100644 --- a/count_word.py +++ b/count_word.py @@ -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 diff --git a/count_word.pyc b/count_word.pyc new file mode 100644 index 0000000..bed0ab9 Binary files /dev/null and b/count_word.pyc differ diff --git a/tests/__init__.pyc b/tests/__init__.pyc new file mode 100644 index 0000000..1935ea8 Binary files /dev/null and b/tests/__init__.pyc differ diff --git a/tests/test_countWord.pyc b/tests/test_countWord.pyc new file mode 100644 index 0000000..c6463f9 Binary files /dev/null and b/tests/test_countWord.pyc differ