SHARE
TWEET

Untitled

a guest Jul 17th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top