编写一个以字母列表为参数的函数。函数应该以相同的顺序返回字母列表,除了元音字母显示为*和任何字母字母显示为%。这是我的解决方案,请告诉我为什么不起作用:
lst [‘s’, ‘a’, ‘l’, ‘l’, ‘y’]
def letter_list(word):
newLetters = []
for char in range(0, len(word) -1):
if char in ‘aeiou’:
char = “ * “
if char.lower() == ‘l’ char = ‘%’ :
newLetters = newLetters + char
return newLetters
print letter_list(“Sally”)
你的问题和解决办法有些模棱两可。你的意思是函数将获取字母/字符列表,但你发送的是整个单词
以下是解决方案:
您的代码不起作用,因为您对字符串和字符使用了所有错误的标记。除此之外,你 地址:
lst
与其元音之间缺少=
“
代替"
‘
和’
代替'
你的缩进是错误的-你必须缩进所有属于你的函数的东西(你应该一致的缩进,而不是4个字符,然后制表符,然后2个字符等等)
您还可以使用理解:
输出:
相关问题 更多 >
编程相关推荐