Write a function called count_word that takes a phrase and a word as arguments and returns a count of the number of occurrences of that particular word in the phrase. The function should return an integer.
Python Script in ATOM or REPL
##while pasting the code indentations/tabs may get disturbed, please refer pic for correct tabs
def count_word(phrase,word):
count=0;
#split the phrase to words;
phrase=phrase.split(" ")
for i in phrase:
if i.lower()==word.lower():
count=count+1;
return count
print(count_word("John loves dogs. John also loves cats.",'John'))
Get Answers For Free
Most questions answered within 1 hours.