spam = ['apples', 'bananas', 'tofu', 'cats']
spam = [] while True: print ('Enter some words into spam:') spam_input = input() if spam_input == '': break spam = spam + [spam_input] def add_and(spam): spam_and = 'and ' + spam[-1] del spam[-1] spam.append(spam_and) spam0 = spam[0] for i in range(len(spam) - 2): spam0 = spam0 + ',' + spam[i + 1] spam_all = spam0 + ',' + spam[-1] print (spam_all) add_and(spam)
本文转载自异步社区。
原文链接:https://www.epubit.com/articleDetails?id=NC7E3EF91D4D0000112EAA4F3CD801CB2