brewersfan1976

ch2-ex7.py

Jul 3rd, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. # searches for a word in a string prints the number of even number of matches in that string
  2.  
  3. string = raw_input("Please enter a sentence:")
  4. print
  5. word = raw_input("Please enter a word to search for:")
  6. print
  7. match = 0
  8.  
  9. for w in string.split():
  10.     if (w == word):
  11.         match = match + 1
  12.        
  13. if (match % 2 == 0):
  14.     print "Number of even number matches for the word", word, "is", match
  15. else:
  16.     print "Number of even number matches for the word", word, "is", match - 1
Advertisement
Add Comment
Please, Sign In to add comment