Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import re
  2.  
  3. def past_verb(text):
  4. # 文字列が空の場合は空文字を返す
  5. if len(text) == 0:
  6. return ""
  7.  
  8. # 不規則動詞の定義
  9. irregular = { "go":"gone", "put":"put" }
  10. # 不規則動詞は辞書を用いて変換する
  11. if text in irregular.keys():
  12. return irregular[text]
  13.  
  14. # 規則動詞の変換
  15. # 問題文のコード例に加え、studyのように末尾がyで末尾から2文字目が
  16. # 子音の場合にも対応している
  17. if text[-1] == "e":
  18. return text + "d"
  19. elif text[-1] == "c":
  20. return text + "ked"
  21. elif text[-1] == "p":
  22. return text + text[-1] + "ed"
  23. elif text[-1] == "y":
  24. if len(text) >= 2 and re.match("[aiueo]", text[-2]):
  25. return text + "ed"
  26. else:
  27. return text[:-1] + "ied"
  28. else:
  29. return text + "ed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement