第八章课后习题
2018-03-21 22:05
281 查看
8-1:def display_message():
print("I am learning function!")
display_message()
8-2:def favorite_book(book):
print("My favorite book is "+book.title())
my_book=input("What's your favorite book?\n")
favorite_book(my_book)
8-5:def describe_city(city,country='China'):
print(city+" is in "+country+".")
describe_city("Shanghai")
describe_city("London","British")
describe_city(city="New York",country="USA")
8-7:def make_album(singer,name,number=0):
if number:
message=singer.title()+" has an album called "+name+" with "+str(number)+" songs!"
else:
message=singer.title()+" has an album called "+name+"."
return message
album1=make_album('Jay','Fantasy')
print(album1)
album2=make_album('Taylor','1984',13)
print(album2)
album3=make_album('Nogizaka46','君の名は希望')
print(album3)
8-10:def show_magicians(magicians):
for magician in magicians:
print(magician)
def make_great(magicians,great):
for magician in magicians:
great.append('the Great '+magician)
magicians=['Mike','Tom','John']
great=[]
show_magicians(magicians)
make_great(magicians,great)
show_magicians(great)
8-14:def make_car(producer,style,**information):
profile={}
profile['producer']=producer
profile['style']=style
for key,value in information.items():
profile[key]=value
return profile
car=make_car('sabaru','outback',color='blue',tow_pack=True)
print(car)
8-15:
printing_functions.py
def print_models(unprinted_designs,completed_models):
while unprinted_designs:
current_design=unprinted_designs.pop()
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("I am learning function!")
display_message()
8-2:def favorite_book(book):
print("My favorite book is "+book.title())
my_book=input("What's your favorite book?\n")
favorite_book(my_book)
8-5:def describe_city(city,country='China'):
print(city+" is in "+country+".")
describe_city("Shanghai")
describe_city("London","British")
describe_city(city="New York",country="USA")
8-7:def make_album(singer,name,number=0):
if number:
message=singer.title()+" has an album called "+name+" with "+str(number)+" songs!"
else:
message=singer.title()+" has an album called "+name+"."
return message
album1=make_album('Jay','Fantasy')
print(album1)
album2=make_album('Taylor','1984',13)
print(album2)
album3=make_album('Nogizaka46','君の名は希望')
print(album3)
8-10:def show_magicians(magicians):
for magician in magicians:
print(magician)
def make_great(magicians,great):
for magician in magicians:
great.append('the Great '+magician)
magicians=['Mike','Tom','John']
great=[]
show_magicians(magicians)
make_great(magicians,great)
show_magicians(great)
8-14:def make_car(producer,style,**information):
profile={}
profile['producer']=producer
profile['style']=style
for key,value in information.items():
profile[key]=value
return profile
car=make_car('sabaru','outback',color='blue',tow_pack=True)
print(car)
8-15:
printing_functions.py
def print_models(unprinted_designs,completed_models):
while unprinted_designs:
current_design=unprinted_designs.pop()
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)
import printing_functions unprinted_designs=['Iphone','Xiaomi','Samsung'] completed_models=[] printing_functions.print_models(unprinted_designs,completed_models) printing_functions.show_completed_models(completed_models)
相关文章推荐
- 教材第八章课后习题 (部分)
- 《C语言程序设计教程》(主编黄迪明、余勤)第八章课后习题答案
- Python课后习题-第八章 读写文件
- Linux Shell编程 从初学到精通 习题答案 课后题答案(第八章)
- c primer plus 第八章 课后习题程序
- 《Python编程 从入门到实践》第八章课后习题
- 《C语言的科学与艺术》课后习题答案第八章(部分)
- C++Primer(第八章课后习题程序题源代码)
- 【RFID第五次作业】第八章课后习题
- 【算法概论】第八章课后习题
- 【RFID第五次作业】第八章课后习题
- 《Algorithms》第八章课后习题8.10题解
- How to think like a Computer Scientist: 课后习题第八章
- 算法概论第八章课后习题
- Java程序设计2 第八章课后习题
- 算法概论第八章课后习题8.8
- [第四周]第八章课后习题
- Python课本第八章课后习题选做
- 算法概论第八章课后习题
- C++ Primer(第五版)课后习题记录 —— 第八章