8-1,消息
def display_message():
print('I studied functions today.')
display_m=essage()
![](https://i-blog.csdnimg.cn/blog_migrate/493043aff8071e9840e6fbd8ae880aa4.png)
8-2,喜欢的图书
def favorite_book(title):
print('My favorite books is "' + title + '".')
favorite_book("Alice in Wonderland")
![](https://i-blog.csdnimg.cn/blog_migrate/15bc1066ca032c03cc5d1162ce68de7a.png)
8-3,T恤
def make_shirt(size, word):
print('This T-shrit is size-' + size + ' with ' + word + ' on it.')
make_shirt('L', 'Hello')
make_shirt(size='X', word='Wrold')
![](https://i-blog.csdnimg.cn/blog_migrate/5f8bf779da68f19d459a3ca8b1e0be30.png)
8-4,大号T恤
def make_shirt(size='L', word='I love pyhton'):
print('This T-shrit is size-' + size + ' with "' + word + '" on it.')
make_shirt(word='Hello')
make_shirt(size='X')
make_shirt()
![](https://i-blog.csdnimg.cn/blog_migrate/63286f741e7f796523766e7e923e80bf.png)
8-7,专辑
def make_album(singer_name, album_name, amount=-1):
dist = {'singer_name':singer_name, 'album_name':album_name}
if amount != -1:
dist['amount'] = amount
return dist
album1 = make_album('Lenka', 'We are the brave')
album2 = make_album('Westlife', 'Greatest Hits')
album3 = make_album('Carpenters', '40/40', 40)
album = [album1, album2, album3]
for i in range(3):
for a, b in album[i].items():
print(a + ":" + str(b))
print()
8-10,了不起的魔术师
def show_magicians(magicians):
for magician in magicians:
print(magician)
def make_great(magicians):
for index, magician in enumerate(magicians):
magicians[index] = magician + " the Great"
magicians = ['xiao ming', 'xiaohong', 'xiao li']
make_great(magicians)
show_magicians(magicians)
8-11,不变的魔术师
def show_magicians(magicians):
for magician in magicians:
print(magician)
def make_great(magicians):
magicians1 = []
for magician in magicians:
magicians1.append(magician + " the Great")
return magicians1
magicians = ['xiao ming', 'xiaohong', 'xiao li']
magicians1 = make_great(magicians[:])
show_magicians(magicians)
show_magicians(magicians1)
8-12,三明治
def sandwiches(*materials):
print('There are ',end='')
for material in materials:
print(material,end=' ')
print()
sandwiches('cheese', 'eggs', 'ham')
sandwiches('mayonnaise', 'lettuce', 'tomatoes')
sandwiches('bread', 'potatoes', 'beef')
8-14,汽车
def make_info(manufacturer , version, **info):
car_info = {'manufacturer':manufacturer, 'version':version}
if info:
for a, b in info.items():
car_info[a] = b
return car_info
car_info = make_info('subaru', 'outback', color='blue', row_package=True)
for a, b in car_info.items():
print(a + ":" + str(b))
8-16,导入
import hello
hello.hello()
from hello import hello
hello()
from hello import hello as hl
hl()
import hello as hl
hl.hello()
from hello import *
hello()