From 2ff5dd627f3153311a330fc7d83077e88d3b26c1 Mon Sep 17 00:00:00 2001 From: bhattbhavesh91 Date: Wed, 21 Jun 2017 04:11:35 +0000 Subject: [PATCH] Done --- count_word.py | 27 +++++++++++++++++++++++++++ count_word.pyc | Bin 0 -> 1117 bytes tests/__init__.pyc | Bin 0 -> 166 bytes tests/test_countWord.pyc | Bin 0 -> 1240 bytes 4 files changed, 27 insertions(+) create mode 100644 count_word.pyc create mode 100644 tests/__init__.pyc create mode 100644 tests/test_countWord.pyc 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 0000000000000000000000000000000000000000..bed0ab9b632ff0a2112afc7a18bc71aed7576b82 GIT binary patch literal 1117 zcmcIkU279T6upzws)JQT9}C{Mg3KS+^AOuUB^rDT|IhAcNj%`FK3`(a2 z@toP{&`uT%(7LqI_@h@i)@O?ND<7KNFb&shdCav_GFUgu__iozEK|k550~L?tHV+P zr$TgupOnb>zusDSkAe=FP>G0FKI41F2NxSP{TAm3&W@d^T1`&~lQa)Rb*bc{_%Jca z>e&^B5tX`@b*XMbsAJ%`OA_Hre5Zsn+Kh4JY=xDO1+`_PU0}I%XPo1wS*^Bkk$9;- zv88N|pG6tTn;J+}+cf@WT9a%l#}6?yux*t+6VzBaj&0@>j*?~yZqSn^Y&%Wadonb9 z=N$+Db6R)cq66n$nD$`ag`KaD;Cuz<4CX6vx(aR`<{ikp@QgCPuc!Nn!oD%M0AS=g z?5|M8eN6^J8g!?V?I+-nT(+hOOB7^jz3Qh`xJ4!nMUu1$N@6d9Qe&GsqsCE^c72M5 z#`w3i8WgrtgA@8L0+}=Ai|3CAq|&Lcg;WD+b2S+G+^fxc77A-NX(;sAq(R?&N^SyZ zn;ULZy~{>Eq!)je46s#pkFBvg>^|dce{q(Zv_Bl?Rt|?B6aOn#|A$(_cv0Crmg-gd K-|$J%RrUw$L_{h8 literal 0 HcmV?d00001 diff --git a/tests/__init__.pyc b/tests/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1935ea83c8d675364b149b655efdd8b0617b1846 GIT binary patch literal 166 zcmZSn%*&sTToe&k)NlVSX`W$o|l`NSE6gGUy@o} jQmh{zpP83g5+APzRKfu?(ju64m1*!w_$^RaD;YZh|O zOF>FxO_DrvM_QwRl0%-xM5u=DC$ z+vqwGhr0osG|P3I+d{`rJ?Duv+sL~7WNK}A`;o6!SF`lGoI3zY zmQu-uRg!U=5TrsiRJYVHz*6_shPsD!2i9)<&f#pV`x{R?lQsoDdkQ2jL$X C`5h4e literal 0 HcmV?d00001