第8章 函数 课后习题

8-2喜欢的图书

def favorite_book(title):
	print("One of my favorite book is "+title+".")

favorite_book("Alice in Wonderland")

8-3T恤

def make_shirt(size,word):
	print("The size of the T-shirt is "+size+" and the word of the T-shirt is "+word+".")

s=input("Please input the size of the T-shirt.\n")
w=input("Please input the word of the T-shirt.\n")

make_shirt(s,w)
make_shirt(word=w,size=s)
8-4大号T恤
def make_shirt(size='L',word='I love Python'):
	print("The size of the T-shirt is "+size+" and the word of the T-shirt is "+word+".")

make_shirt()
make_shirt("M")
make_shirt("XL","Happy!")

8-7专辑
def make_album(singer,album,num=0):
	if(num):
		return {'singer':singer,'album':album,'num':num}
	else:
		return {'singer':singer,'album':album}

album1=make_album('Alice','Sun',5)
album2=make_album('Bob','Wide')
album3=make_album('Lily','Quiet',4)
print(album1)
print(album2)
print(album3)
8-8用户的专辑
def make_album(singer,album,num=0):
	if(num):
		return {'singer':singer,'album':album,'num':num}
	else:
		return {'singer':singer,'album':album}
	

album1=make_album('Alice','Sun',5)
album2=make_album('Bob','Wide')
album3=make_album('Lily','Quiet',4)
print(album1)
print(album2)
print(album3)

flag=True
while flag:
	singer=input("Please input the singer name(input E for exit)\n")
	if(singer=='E'):
		break
	album=input("Please input the albunm name\n")
	print(make_album(singer,album))
8-9魔术师
def show_magicians(magicians):
	for magician in magicians:
		print(magician)

magicians=['Alice','Bob','Cindy','David','Lily']
show_magicians(magicians)
8-10了不起的魔术师
def show_magicians(magicians):
	for magician in magicians:
		print(magician)

def make_great(magicians):
	num=len(magicians)
	i=0
	while i<num:
		magicians[i]='the Great '+magicians[i]
		i=i+1

magicians=['Alice','Bob','Cindy','David','Lily']
show_magicians(magicians)
make_great(magicians)
print('\n')
show_magicians(magicians)
8-11不变的魔术师
def show_magicians(magicians):
	for magician in magicians:
		print(magician)

def make_great(magicians):
	num=len(magicians)
	i=0
	while i<num:
		magicians[i]='the Great '+magicians[i]
		i=i+1
	return magicians

magicians=['Alice','Bob','Cindy','David','Lily']
show_magicians(magicians)
new_magicians=make_great(magicians[:])
print('\n')
show_magicians(new_magicians)
print('\n')
show_magicians(magicians)
8-14汽车
def make_car(manufacturer,type,**keys):
	car={"manufacturer":manufacturer,"type":type}
	for key,value in keys.items():
		car[key]=value
	print(car)

car = make_car('subaru', 'outback', color='blue', tow_package=True)








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值