Menu Close

Word Count

Write a Python program to count the number of entered words in a given string.
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
Input:
First Line: String or sentence
Second Line: word to be searched in the sentence

Output:
Word Count

string=input("Enter a sentence: ")
find=input("Enter the word: ")
L=string.split()
s=0
for i in range(len(L)):
  if L[i]==find:
    s+=1
print('Count=',s)

Exec. on linux

Morae!Q!