Computer Science, asked by singhchauhanabhay56, 3 months ago

Write a program in python to accept a string from the user count number of words in the string also count the word “to” in the string (not case sensitive).
Example: Never be afraid to trust an unknown future to a known God.
Output Number of words in the string are : 12
Number of times ‘to’ has appeared in the string : 2

Answers

Answered by dhruvgandhi200
0

Answer:

Approach 1 − Using split() function. Split function breaks the string into a list iterable with space as a delimiter. ...

Approach 2 − Using regex module. Here findall() function is used to count the number of words in the sentence available in a regex module. ...

Approach 3 − Using sum()+ strip()+ split() function.

Similar questions