我需要创建一个函数,该函数传递多个列表并返回一个字符串,然后进行打印。老实说,我甚至不知道我是否朝着正确的方向前进
wordlist = ['new', 'barn', 'shark', 'hold', 'art', 'only', 'eyes'],
['subtract', 'add'],
['girl', 'house', 'best', 'thing', 'easy', 'wrong', 'right', 'again', 'above'],
['question'],
[]
def createSentence(wordlist):
if len(wordlist) > 1:
return 'The ' + str(len(wordlist)) + ' sight words for this week are ' + wordlist + '.'
elif len(wordlist) == 1:
return 'The only sight word for this week is' + wordlist + '.'
elif len(wordlist) == 0:
return 'There are no new sight words for this week!'
print(createSentence(wordlist))
而且我认为我的清单应该是这样的
week2 = ['new', 'barn', 'shark', 'hold', 'art', 'only', 'eyes']
week5 = ['subtract', 'add']
week10 = ['girl', 'house', 'best', 'thing', 'easy', 'wrong', 'right', 'again', 'above']
week13 = ['question']
week17 = []
但我不知道如何将它们传递给函数
我认为您可能希望使用join函数将列表转换为字符串
(“,”).join(单词列表)
第2周的输出:
'The 7 sight words for this week are new ,barn ,shark ,hold ,art ,only ,eyes.'
我建议采取不同的方法,为您的数据创建一个数据结构(在本例中为字典):
输出
像这样:
输出:
相关问题 更多 >
编程相关推荐