Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def past_verb(text):
- # 文字列が空の場合は空文字を返す
- if len(text) == 0:
- return ""
- # 不規則動詞の定義
- irregular = { "go":"gone", "put":"put" }
- # 不規則動詞は辞書を用いて変換する
- if text in irregular.keys():
- return irregular[text]
- # 規則動詞の変換
- # 問題文のコード例に加え、studyのように末尾がyで末尾から2文字目が
- # 子音の場合にも対応している
- if text[-1] == "e":
- return text + "d"
- elif text[-1] == "c":
- return text + "ked"
- elif text[-1] == "p":
- return text + text[-1] + "ed"
- elif text[-1] == "y":
- if len(text) >= 2 and re.match("[aiueo]", text[-2]):
- return text + "ed"
- else:
- return text[:-1] + "ied"
- else:
- return text + "ed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement