brewersfan1976

ch4-ex4.py

Aug 2nd, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. # A very simple grammar check program. if user types between you and I
  2. # it will tell the user the correct grammar is between you and me
  3. # it searches for the words between, for and with. It will then replace
  4. # I with me, he with him and she with her.
  5.  
  6. import re
  7.  
  8. userInput = raw_input("Please enter a sentence: ")
  9.  
  10. if re.search ("between you and I", userInput):
  11.    print "the correct grammar is:"
  12.    print re.sub ("I", "me", userInput)
  13.    
  14. if re.search ("for you and I", userInput):
  15.    print "the correct grammar is:"
  16.    print re.sub ("I", "me", userInput)
  17.  
  18. if re.search ("with you and I", userInput):
  19.    print "the correct grammar is:"
  20.    print re.sub ("I", "me", userInput)
  21.  
  22. if re.search ("between you and he", userInput):
  23.    print "the correct grammar is:"
  24.    print re.sub ("he", "him", userInput)
  25.  
  26. if re.search ("for you and he", userInput):
  27.    print "the correct grammar is:"
  28.    print re.sub ("he", "him", userInput)
  29.  
  30. if re.search ("with you and he", userInput):
  31.    print "the correct grammar is:"
  32.    print re.sub ("he", "him", userInput)
  33.  
  34. if re.search ("between you and she", userInput):
  35.    print "the correct grammar is:"
  36.    print re.sub ("she", "her", userInput)
  37.  
  38. if re.search ("for you and she", userInput):
  39.    print "the correct grammar is:"
  40.    print re.sub ("she", "her", userInput)
  41.  
  42. if re.search ("with you and she", userInput):
  43.    print "the correct grammar is:"
  44.    print re.sub ("she", "her", userInput)
Advertisement
Add Comment
Please, Sign In to add comment