0

I am writing a Python Program where I can get the location of the word in a paragraph and the number of times the word has appeared in the paragraph included in the program. Currently, my code only outputs 2 locations of a word entered.

text = '''This is sample text to test if this pythonic program can 
serve as
an indexing platform for finding words in a paragraph. It can give 
values
as to where the word is located with the different examples as 
stated'''

find_str = input("Please Enter Word to Search: ")
x = 0
i = text.find(find_str, x)
print (i)
i = text.find(find_str, i+1)
print (i)

If I enter "as", this is the output:

Please Enter Word to Search: as
63
140
>>> 

How do I make the code output all of the locations of the entered word, and additionally the number of times the word has appeared in the paragraph?

applehacker321
  • 35
  • 1
  • 1
  • 4

0 Answers0