Question: This code is for python. Part B Write a function that counts the number of occurances of a given word in a given sentence. Your

This code is for python. Part B Write a function that countsThis code is for python.

Part B Write a function that counts the number of occurances of a given word in a given sentence. Your function should return an integer number for the number of occurrences of the word. Also depending on what the value of case_sensitive is the function should return the correct count. For example if case_sensitive is set to True then Car should not be counted the the sentence "This is a car" and return 0, but it is set to False then function should return 1. This function should: be named count_occurences take 2 positional arguments: both are strings, first one is the word and the second one is the sentence take 1 optional argument: a default argument case_sensitive set to True. return an integer number: the number of occurences of the first string in the second string In this function, you should loop through each word(token) in the sentence, and check if it is the same as the given word, if the condition is true then increment the count by 1 and return count at the end. HINT: You may use split() method but no other imports are allowed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!