私の質問:識別子には順序がありますか?
私はこの練習をしています。
If the verb ends in e, drop the e and add ing (if not exception: be, see, flee, knee, etc.)
If the verb ends in ie, change ie to y and add ing
For words consisting of consonant-vowel-consonant, double the final letter before adding ing
By default just add ing
この演習であなたの仕事は、不定詞の形で動詞が現在分詞の形を返す、指定された関数make_ing_form()を定義することです。嘘、見て、動かし、抱きしめるなどの言葉であなたの機能をテストしてください。ただし、すべてのケースでこのような単純なルールが機能するとは限りません。
私のコード:このコードで
def make_ing_form():
a = raw_input("Please give a Verb: ")
if a.endswith("ie"):
newverb = a[:-2] + "y" + "ing"
elif a.endswith("e"):
newverb = a[:3] + "ing"
elif a[1] in "aeiou":
newverb = a + a[-1] + "ing"
else:
newverb = a + "ing"
print newverb
make_ing_form()
すべてが腸ですが、私は配置を変更したとき。
def make_ing_form():
a = raw_input("Please give a verb: ")
if a.endswith("e"):
newverb = a[:3] + "ing"
elif a.endswith("ie"):
newverb = a[:-2] + "y" + "ing"
elif a[1] in "aeiou":
newverb = a + a[-1] + "ing"
else:
newverb = a + "ing"
print newverb
make_ing_form()
別のステートメント(からの場合のElifまで)に識別子の変更は、それが「忘れて」私はここにhttp://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#python-has-namesを理解する方法を現在分詞、上にない来る答えは、その.IF if文はケースですなぜ私はこの結果を受け取るのですか?
私の英語について申し訳ありません....
2番目のコードはプレースメント以上に変更されています。それは 'aeiou 'の' elif a: 'を持っています。しかし、最初のバージョンからの正しい出力と2番目のバージョンからの誤った出力を与えるサンプル入力を与えることができますか? – doctorlove
お返事ありがとうございます。最初の例では、私はうそを書いています。私はうそをついていますが、二番目の例は私が嘘をついて来るのです。 – d68745
はい、申し訳ありませんが、私は書き換えることを忘れています... – d68745