Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # searches for a word in a string prints the number of even number of matches in that string
- string = raw_input("Please enter a sentence:")
- print
- word = raw_input("Please enter a word to search for:")
- print
- match = 0
- for w in string.split():
- if (w == word):
- match = match + 1
- if (match % 2 == 0):
- print "Number of even number matches for the word", word, "is", match
- else:
- print "Number of even number matches for the word", word, "is", match - 1
Advertisement
Add Comment
Please, Sign In to add comment