python作业(7)

8-2 喜欢的图书:

    代码如下:

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

favorite_book("Alice in Wonderland")


    运行结果:

    


8-3 T-shirt:

    代码如下:

def make_shirt(_title,size):
	print('"'+_title.title()+'"'+'will be printed on the shirt, and the size is '+size+". ")

make_shirt("Alice in Wonderland",'L')
make_shirt(size="M",_title='Hello world')




    结果如下:

    


8-4 大号T-shirt:

     代码如下:

def make_shirt(_title="I love Python",size="T"):
	print('"'+_title.title()+'"'+'will be printed on the shirt, and the size is '+size+". ")

make_shirt()
make_shirt(size="M")
make_shirt(_title='Hello world')





    结果如下:

    


8-6 城市名:

    代码如下:

def city_country(city,country):
	return city+", "+country

s1=city_country('Beijing','China')
s2=city_country('Tokyo','Japen')
s3=city_country('Califonia','U.S.')
print(s1)
print(s2)
print(s3)



    结果如下:

    


8-7 专辑:

    代码如下:

def make_album(name,singer,num=""):
	if num:
		album={'name':name, 'singer':singer, 'num':num}
	else:
		album={'name':name, 'singer':singer}
	return album

album1=make_album("Symphony of Fate","Beethoven")
album2=make_album("Waiting For End Of Your Class","Jame Zhou","2")
print(album1)
print(album2)




    结果如下:

    

8-9 8-10 8-11 魔法师们:

    代码如下:

def show_magicians(mags):
	for mag in mags:
		print(mag,end="  ")
	print("")
def make_great(mags):
	mag2=[]
	for mag in mags:
		mag="the Great "+mag
		mag2.append(mag)
	mags.clear()
	for mag in mag2:
		mags.append(mag)
print("8-9 and 8-10 :")
mags=["Mike","John","Lily"]
show_magicians(mags)
make_great(mags)
show_magicians(mags)
print("8-11 :")
mags=["Mike","John","Lily"]
show_magicians(mags)
make_great(mags[:])
show_magicians(mags)

    运行结果:

    


8-14 汽车:

    代码如下:

def make_car(_producer,size,**other):
	car={}
	car['producer']=_producer
	car['type']=size
	for key,value in other.items():
		car[key]=value
	return car

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



    结果如下:

    




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值