【发布时间】:2020-10-10 19:55:10
【问题描述】:
我说得对:
需要我的输出看起来像这样:
本周的 7 个视觉词是 new、barn、shark、hold、art、only、和 eyes。 本周的 2 个常用词是减法、和加法。 本周的 9 个常用词分别是女孩、房子、最好、事情、容易、错误、正确、再次、上面的和。 本周唯一的视觉词是问题。 本周没有新的视觉词!
但我想知道需要在返回中添加的最后一个词之前的“和”。这样合适吗?
这是代码:
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:
wordlist[-1] = "and " + wordlist[-1]
return f'The {len(wordlist)} sight words for this week are {", ".join(wordlist)}.'
elif len(wordlist) == 1:
return f'The only sight word for this week is {wordlist[0]}.'
elif len(wordlist) == 0:
return 'There are no new sight words for this week!'
for lst in wordlist:
print(createSentence(lst))
【问题讨论】:
-
进行了调整。