0
A
回答
0
調整這3個功能:
def starts_with_vowel(word):
# return True if the word starts with a vowel and False otherwise
return word[0] in ['a', 'e', 'i', 'o', 'u']
def encode(word):
# translate a single word to the secret language
# call starts with vowel to decide which pattern to follow
if starts_with_vowel(word):
return word[1:] + word[0] + 'ar'
else:
return word + 'way'
def translate(message):
# translate the whole text to the secret language
# call encode to translate individual words in text
return ' '.join(encode(word) for word in message)
最大的問題是encode()
和starts_with_vowel()
通過所有單詞迭代(但您的評論說,它應該在一個字工作)的編碼
2
你忘了translate
功能分配:
必須是:
phrase = ' '.join(encode(message))
return phrase
2
除了@ delimitry的回答,也改變了話到字在第二個功能,即如果條件,改變 -
if starts_with_vowel(words):
到 -
if starts_with_vowel(word):
相關問題
- 1. 在python中運行程序的程序
- 2. python程序中的速度程序
- 3. 相當於Python中的程序的Python
- 4. Python中的閏年程序
- 5. virtualenv中的非python程序
- 6. python 3.6中的Bruteforce程序
- 7. Python 2.7中的程序
- 8. python程序中的sendmail
- 9. Python中的程序驗證
- 10. 的Python程序
- 11. Python程序的Python包裝
- 12. 的Python /僞程序
- 13. 如何中斷python程序?
- 14. 如何在python中打開python程序
- 15. Python Scrambler程序
- 16. 在Python程序
- 17. Python中的程序實例的隊列?
- 18. 修改python程序(python 2.7)
- 19. Python中的統計引導程序庫?
- 20. python中的緩慢蠻力程序
- 21. Python中的鐵路預訂程序
- 22. 在Python中進行比較的程序
- 23. python中的格式化程序
- 24. Python中的程序循環2.7
- 25. python程序中的語法無效
- 26. Python程序中的空白區域
- 27. python中的基本計算器程序
- 28. python 3.3.2中的程序語法錯誤?
- 29. python程序中的命令行選項
- 30. 調用C中的Python函數++程序
函數只處理第一個單詞然後返回。您應該創建一個空列表pattern = [],然後爲每個單詞調用pattern.append(word [1:] + word [0] +'ar')或pattern.append(word +'way'),然後返回pattern等結束了 – samgak