Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python h/w help
#1
Hi all,
can i get a bit of help with my H/W, the task is as follows:
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 position 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.
Analyse the requirements for this system and design, develop, test and evaluate a program to locate and return the position(s) of the word you have selected in a particular sentence or return an error message if the word is not in the sentence.
 
Heres what i've done so far -

sentence= input ("Enter a sentence that contains several words, without punctuation.")

print(sentence)

sentence.split(' ')

word=input("please enter a word from the sentance and its position shall be displayed")

if word in sentence:

    print ("found word")

else:

    print ("word not found")
My problem is that the code wont tell me the position of a word in the sentence and that the code is not case - insensitve.
Any help would be appreciated.
Reply


Messages In This Thread
Python h/w help - by tahmid909 - Oct-01-2016, 10:17 AM
RE: Python h/w help - by wavic - Oct-01-2016, 10:56 AM
RE: Python h/w help - by j.crater - Oct-01-2016, 10:29 AM
RE: Python h/w help - by tahmid909 - Oct-01-2016, 10:46 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020