我的問題:標識符中有訂單嗎?
我有這個練習;
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()
答案誰我來是不是現在分詞,我這裏怎麼理解http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#python-has-names,當標識符變化到另一份聲明(從如果到艾利芙),它「忘記」 if語句。如果是這樣的話,爲什麼我收到這個結果?
我的英語對不起....
第二個代碼變化超過展示位置;它有一個「aeiou」:'。但是,您可以給出一個示例輸入,它提供第一個版本的正確輸出和第二個輸出的錯誤輸出? – doctorlove
謝謝你的回答,第一個例子,我寫謊言,我來說謊,但第二個例子我來說謊 – d68745
是的,對不起,我忘了[1]寫,我改變現在... – d68745