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

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

#coding:gbk

#8-15打印模型

#printing_functions.py
def print_models(unprinted_designs, completed_models):
	"""
	模拟打印每个设计,直到没有未打印的设计为止
	"""
	while unprinted_designs:
		current_design = unprinted_designs.pop()
		
		#模拟根据设计制作3D打印模型的过程
		print("Printing model: " + current_design)
		completed_models.append(current_design)
		
def show_completed_models(completed_models):
	"""显示打印好的所有模型"""
	print("\nThe following models have been printed: ")
	for completed_model in completed_models:
		print(completed_model)

#print_models.py

#首先创建一个列表,其中包含一些要打印的设计
unprinted_designs = ['iphone case','robot pendant', 'dodecachedron']
completed_designs = []

#模拟打印每个设计,知道没有未打印的设计为止
# 打印每个设计后,都将其移到列表completed_models中
while unprinted_designs:
	current_design = unprinted_designs.pop()
	
	#模拟根据设计制作3D打印模型的过程
	print("Printing model: " + current_design)
	completed_designs.append(current_design)
	
# 显示打印好的所有模型
print("\nThe following models have been printed: ")
for completed_design in completed_designs:
	print(completed_design)

#重新组织
from printing_functions import print_models
from printing_functions import show_completed_models
#或from printing_functions import *
#import printing_functions不行

unprinted_designs = ['iphone case','robot pendant','dodecahedron']
completed_models = []

print_models(unprinted_designs[:],completed_models)
show_completed_models(completed_models)

#8-16导入
#making_car.py
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


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

from making_car import *
car_info = making_cars('audi','large',made_in = 'china' , color = 'blue')
print(car_info)

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

from making_car import making_cars as mc
car_info = making_cars('audi','large',made_in = 'china' , color = 'blue')
print(car_info)

import making_car as maca
car_info = making_cars('audi','large',made_in = 'china' , color = 'blue')
print(car_info)

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




©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页