我正在学习 'Python自动化办公教程'。我无法弄清如何从下面的程序中删除最终输出逗号。目标是不断提示用户输入值,然后将其打印在列表中,并在结尾处插入“和”。输出应该类似于这样:
我的看起来像这样:
那个最后的逗号让我疯了。
apples, bananas, tofu, and cats
我的看起来像这样:
apples, bananas, tofu, and cats,
那个最后的逗号让我疯了。
def lister():
listed = []
while True:
print('type what you want to be listed or type nothing to exit')
inputted = input()
if inputted == '':
break
else:
listed.append(inputted+',')
listed.insert(-1, 'and')
for i in listed:
print(i, end=' ')
lister()