您的位置:首页 > 编程语言 > Python开发

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 入门