I'm writing a program where the user has to enter a set of string characters. They then pick a keyword that may or may not be in the string. If it is then the program will run through the string and see how many times the keyword appear and it will print this to the screen. I have done this so it does it but if the keyword appears twice. How do I get it so if the word appears twice then the program will print all positions of it?
This is what i have so far:
#Start by making a string
String = input("Please enter a set of string characters.\n")
#Make the user choose a keyword
Keyword = input("Please enter a keyword that we can tell you the position of.\n")
#Split the string into single words assigning the position to the word after the space
IndivualWords = String.split(' ')
#Start an IF statement
if Keyword in IndivualWords:
#If the IF is true then access the index and assign the keyword a position
pos = IndivualWords.index(Keyword)
#Print the position of the word
print (pos +1)
else:
#Print an error
print("That word is not in the string.")