Python编程:从入门到实践第八章练习8.5

Python编程:从入门到实践第八章练习8.5

快要做完8-12的时候,镜片突然就从眼睛上掉下来,手一摸,镜框都裂开了,我人也裂开了;
原来,打代码不仅费眼睛,还费眼镜…哎

#coding:gbk

#8-12三明治
def making_sandwiches(*addings):
	"""打印顾客点的所有食材"""
	print("\nMaking sanwiches with following food: ")
	for adding in addings:
		print(adding)
		
making_sandwiches('pepperroni','egg','sausage')
making_sandwiches('extra cheese','peppers','mushrooms')
making_sandwiches('pepperoni','bacon','beaf')

#8-13用户简介
def build_profile(first,last,**user_info):        ##形参**user_info中的两个型号让python创建一个名为user_info的空字典,并将收到的所有名称-值对都封装到这个字典中。
	"""创建一个字典,其中包含我们所知道的有关用户的一切"""
	profile = {}
	profile['first_name'] = first
	profile['last_name'] = last
	for key,value in user_info.items():      #遍历字典user_info中的键-值对,并将每个键-值对都加入到字典profile中
		profile[key] = value
	return profile                          #最后,将字典profile返回给函数调用行
	
user_profile = build_profile('john','su',
                             location = 'Amoy',
                             field = 'economy',
                             living = 'fuzhou')
print(user_profile)

#8-14汽车
def making_cars(brand,size,**cars_info):
	"""打印汽车信息"""
	cars = {}
	cars['brand'] = brand
	cars['size'] = size
	for key,value in cars_info.items():
		cars[key] = value
	return cars

car_info = making_cars('audi','large',made_in = 'china' , color = 'blue')
print(car_info)



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值