Oct-25-2017, 09:17 PM
Hi i have a problem with my homework i cant get the code to give me the pisition of the word.
The question is :
Develop a program that analyses a sentence that contains several words without punctuation. When a word in that sentence is input, the program identifies all of the positions where the word occurs in the sentence. The system should not be case sensitive: Ask, ask, ASK should be treated as the same word.
For example, in the sentence “ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY”
The word ‘COUNTRY’ occurs in the 5th and 17th positions.
The question is :
Develop a program that analyses a sentence that contains several words without punctuation. When a word in that sentence is input, the program identifies all of the positions where the word occurs in the sentence. The system should not be case sensitive: Ask, ask, ASK should be treated as the same word.
For example, in the sentence “ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY”
The word ‘COUNTRY’ occurs in the 5th and 17th positions.
sentence = input("write a long sentence please ") sentence.split(" ") palabra = input("Please enter a word from the sentance and the position of the word you typed in will be displayed on the screen ") if palabra in sentence: print("we have found the word u are looking for ") else: print("The word you are looking for it's not in the sentence ")