#-*-coding:utf-8 -*-
# 8-1
def
display_message
():
print
(
'function!'
)
# 8-2
def
favorite_book
(
title
):
print
(
'One of my favorite book is'
,title)
# 8-3
def
make_shirt
(
size
,
words
):
print
(
'T-shirt:'
,words,size)
make_shirt(
8
,
'i can fly'
)
make_shirt(
size
=
9
,
words
=
'404 not found'
)
# 8-4
def
make_shirt
(
size
=
'big'
,
words
=
'i love you'
):
print
(
'T-shirt:'
,words,size)
make_shirt()
make_shirt(
'middle'
)
make_shirt(
words
=
'dfsdf'
)
# 8-5
def
describe_city
(
name
,
country
=
'china'
):
print
(name,
'is in'
,country)
describe_city(
'shanghai'
)
describe_city(
'new York'
,
'USA'
)
describe_city(
'beijing'
)
# 8-6
def
city_country
(
city
,
country
):
return
'"'
+
city
+
','
+
country
+
'"'
print
(city_country(
'beijing'
,
'china'
))
print
(city_country(
'Santiago'
,
'Chile'
))
print
(city_country(
'new_york'
,
'USA'
))
# 8-7
def
make_album
(
name
,
album
):
return
{
'name'
:name,
'album'
:album}
print
(make_album(
'xxx'
,
'yyy'
))
print
(make_album(
'zhou'
,
'dao'
))
print
(make_album(
'lady_'
,
'crazy'
))
# 8-8
while
True
:
n
=
input
(
'name:'
)
a
=
input
(
'album:'
)
if
n
==
'q'
or
a
==
'q'
:
break
else
:
print
(make_album(n,a))
# 8-9
def
show_magicians
(
name
):
for
i
in
name:
print
(i)
# 8-10
def
make_great
(
n
):
l
=
[]
for
i
in
n:
i
=
'the great '
+
i
l.append(i)
n
=
l[:]
a
=
[
'xyz'
,
'abc'
,
'lmn'
]
make_great(a)
show_magicians(a)
# 8-11
a
=
[
'xyz'
,
'abc'
,
'lmn'
]
def
make_great
(
n
,
m
):
for
i
in
n:
i
=
'the great '
+
i
m.append(i)
b
=
[]
make_great(a,b)
show_magicians(a)
show_magicians(b)
# 8-12
def
pizza
(
*
i
):
for
n
in
i:
print
(n)
pizza(
'aaa'
,
'bbb'
,
'ccc'
)
pizza(
'333'
,
'444'
,
'555'
)
pizza(
'123'
,
'234'
,
'345'
)
# 8-13
def
build_profile
(
first
,
last
,
**
user_info
):
profile
=
{}
profile[
'first_name'
]
=
first
profile[
'last_name'
]
=
last
for
key, value
in
user_info.items():
profile[key]
=
value
return
profile
p
=
build_profile(
'xiao'
,
'jianzhe'
,
hobbey
=
'football'
,
skills
=
'none'
,
weight
=
'secret'
)
print
(p)
# 8-14
def
make_car
(
manufacturer
,
model
,
**
m
):
car_l
=
{}
car_l[
'manufacturer'
]
=
manufacturer
car_l[
'model'
]
=
model
for
k,v
in
m:
car_l[k]
=
m
return
car_l
car
=
make_car(
'subaru'
,
'outback'
,
color
=
'blue'
,
tow_package
=
True
)
print
(car)
# 8-15
# 加上 from printing_model import * 即可