《Python编程快速上手——让繁琐工作自动化》作业-4.10.1 逗号代码
【摘要】 spam = ['apples', 'bananas', 'tofu', 'cats']spam = [] while True: print ('Enter some words into spam:') spam_input = input() if spam_input == '': break spam = spam + [spam_i...
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
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)