8-3 T恤
def make_shirt(size,name):
print("The size of this shirt is " + size)
print("The shirt says "+name)
make_shirt('small','python')
make_shirt(name='python',size='small')
8-5 城市
def describe_city(city,nation='China'):
print(city +' is in '+nation)
describe_city('Beijing')
describe_city('Shanghai')
describe_city('London','Britain')
8-7 专辑
def make_album(name,album_name,number=''):
person={'first':name,'second':album_name}
if number:
person['number']=number
return person
album1=make_album('Taylor Swift','reputation','15')
album2=make_album('Ed Sheeran','Divide')
album3=make_album('Lorde','Melodrama')
print(album1)
print(album2)
print(album3)
8-8 用户的专辑
def make_album(name,album_name):
person={'first':name,'second':album_name}
return person
while True:
name=input("the name of the singer is: ,print q to quit")
if name=='q':
break
album_name=input("the name of the album is: ,,print q to quit")
person=make_album(name,album_name)
print(person)
8-9 魔术师
def show_magicians(names):
for name in names:
print(name)
names=['Mike','Dan','Joe']
show_magicians(names)