#8.7
给函数make_album()添加一个可选形参,以便能够储存专辑包含的歌曲数。
def make_album(singer,album,numbers=‘’):#形参3中间没有空格
music={‘singer name’:singer,‘album name’:album}
if numbers:
music[‘numbers’]=numbers
return music
a=make_album(“zhangsan”,‘fly’,1)
print(a)
b=make_album(‘lisi’,‘try’)
print(b)
c=make_album(‘wangwu’,‘sky’)
print©
#练习8.8用户的专辑
def hanshu(value1,value2):
zidian={‘singer’:value1,‘album’:value2}
return zidian
while True:
print(“\nPlease tell me about your favorite album.”)
print(“(enter ‘q’ to quit at any time)”)
a=input("\nYour favorite singer is:")
if a=='q':
break
b=input("Your favorite album of the singer is:")
if b=='q':
break
c=hanshu(a,b)
print("\nYour favorite singer is "+a+".")
print("Your favorite album of the singer is "+b+".")
print(c)