Python 学习记录[一]
2018-01-27 00:25
267 查看
需求
编写一个while循环,让用户输入一个专辑的歌手,名称和专辑歌曲数量(选填),获取输入的信息,并且在退出之前打印这些专辑,要求过滤重复的专辑。在这个while循环中,务必要提供退出途径。逻辑图:
Created with Raphaël 2.1.0开始提示用户输入输入的是exit?专辑列表有元素?专辑元素去重打印专辑列表中的元素结束将用户输入的内容存入到列表中yesnoyesno代码块
def make_album(singer,album_name,size=''): album_1 = {} album_1["singer"]=singer album_1["album_name"]=album_name if(size): album_1["size"]=int(size) return album_1 tips='please enter singer and album name, split with ",", enter exit to exit this program:\n' flag = True album_list=[] new_list=[] while flag: info = raw_input(tips) flag = info!="exit" if (not flag): if(len(album_list)>0): for item in album_list: #remove duplicated album from list temp = item album_list.remove(temp) while(temp in album_list): album_list.remove(temp) new_list.append(temp) print("singer:{},album:{},size:{}".format(item["singer"],item["album_name"],item["size"])) break; else: info_list = info.split(","); if len(info_list)==3: item = make_album(info_list[0],info_list[1],info_list[2]) album_list.append(item) elif len(info_list)==2: item = make_album(info_list[0],info_list[1]) album_list.append(item) else: print("please check your input, thanks") continue
相关文章推荐
- Python数据结构与算法分析学习记录(1)——基于Problem Solving with Algorithms and Data Structures using Python的学习
- Python学习记录七---继承、多态和封装
- Python学习记录(一)
- Python学习记录4(语句)
- Python模块学习 ---- logging 日志记录(一)
- Python Django 学习知识点记录
- Python学习记录-2016-12-20
- 7、Python3 函数学习记录
- DayDayUP_Python自学记录[5]_dict和set学习
- python学习记录:序列
- python学习记录 一
- Python学习记录-2016-12-1
- python学习记录:元组
- [Deep Learning]学习记录1-Python实现神经网络BP算法
- Python学习入门基础教程(learning Python)--5.7 Python文件数据记录存储与处理
- Ubuntu中python环境下import requests错误的解决(学习过程问题记录)
- 流畅的python第十四章可迭代的对象,迭代器和生成器学习记录
- 【Python学习记录】2015-02-17
- Python 学习记录1
- 记录学习python的学习网站