on-internet
← Community

Can't get program to print "not in sentence" when word not in sentence

Stack Overflow ·

I have a program that asks for input of a sentence, then asks for a word, and tells you the position of that word: sentence = input("enter sentence: ").lower() askedword = input("enter word to locate position: ").lower() words = sentence.split(" ") for i, word in enumerate(words): if askedword == word : print(i+1) #elif keyword != words : #print ("this not") However I cannot get the program to work correctly when I edit it to say that if the input word is not in the sentence, then print "this isn't in the sentence"

Comments

Sign in or sign up to comment and upvote.

No comments yet.