furas

Python - if not found - (FB: learnpython.org)

Jan 11th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. sentence = input("Enter a sentence: ")
  2.  
  3. keyword = input("Input a keyword from the sentence: ")
  4.  
  5. words = sentence.split()
  6.  
  7. found = False
  8.  
  9. for i, word in enumerate(words, 1):
  10.     if keyword.lower() == word.lower():
  11.         print("This word appears in sentence in position", i)
  12.         found = True
  13.  
  14. if not found:
  15.     print("not in sentence")
Add Comment
Please, Sign In to add comment