1. 知识点
![](https://i-blog.csdnimg.cn/blog_migrate/47debf616396ae0dcca167266caab856.png)
2. 练习·
# 练习8.1
def display_message():
print("theme")
display_message()
# 练习8.2
def favorite_book(title):
print(f"one of my favorite book is {title}")
print("please imput your favorite book")
title = input()
favorite_book(title)
# 练习 8.3
def make_shirt(size,words):
print(f"shirt's size is {size} and words is \"{words}\" ")
make_shirt("xl","happy")
# 练习 8.4 大号T
def make_shirt(size,words="i ove python"):
print(f"shirt's size is {size} and words is \"{words}\" ")
make_shirt("xl")
make_shirt("l")
make_shirt("s","happy")
# 练习8.5 城市
def describe_city(name,coutry="China"):
print(f"{name.title()} is in {coutry.title()}")
describe_city("Xian")
describe_city("hunan")
describe_city("London","England")
def build_person (first_name,last_name,age=None):
person={'first':first_name, 'last':last_name}
if age:
person['age']=age
return person
musician=build_person('jia','chen','24')
print(musician)
# 练习8.6 城市名
def describe_city(name,coutry):
print(f"{name.title()} , {coutry.title()}")
describe_city("Xian","China")
describe_city("London","England")
# 练习8.7 专辑
def make_album(singer, name, number='None'):
album={"Singer":singer, 'Name':name}
if number:
album['Number']=number
return album
Album=make_album("vava","cake","9")
print(Album)
Album=make_album("gai","caker","4")
print(Album)
# 练习8.8 用户的专辑
def make_album(singer, name, number='None'):
album={"Singer":singer, 'Name':name}
if number:
album['Number']=number
return album
while True:
singer=input("tell me the singer of album\n")
if singer=='q':
break
name=input("tell me the name of album\n")
if name=='q':
break
Album = make_album(singer, name)
print(Album)
# 练习8.9
messages=['hello','bye','see you','watch out']
send_messages=[]
def show_message(messages,send_messages):
for message in messages:
print(message)
send_messages.append(message)
def send_message(send_messages):
for send_message in send_messages:
print(send_message)
show_message(messages[:],send_messages)
send_message(send_messages[:])
# 练习8.10 消息归档
# 练习8.12 三明治
def make_sandwich(*toppings):
print("Making a sandwich with the following toppings ")
for topping in toppings:
print(f"- {topping}")
make_sandwich('tomato','egg','potato')
# 练习8.13 用户简介
def build_profile(first, last,**user_info):
user_info['first_name']=first
user_info['last_name']=last
return user_info
user_profile=build_profile('shao', 'tang', location='tianjing', field=' construction',weigh='210')
print(user_profile)
# 练习8.14 汽车
def make_car(maker,size ,**imformation):
imformation['Manufacturers']=maker
imformation['Models']=size
return imformation
car=make_car('subaru','outback',color='blue',tow_package=True)
print(car)