#coding:gbk
#8-1消息
def display_message():
"""展示在本章中的学习内容"""
print('你在本章的学习内容')
display_message()
#8-2喜欢的图书
def favorite_book(title):
print('One of my favoriate books is ' + title.title())
favorite_book('alice in wonderland')
#8-3 T-shirt
def make_shirt(shirt_size, shirt_typeface):
"""说明T shirt的尺寸和字样"""
print('\nThe size of T-shirt is ' + shirt_size + '.')
print('The typeface of the T-shirt is ' + shirt_typeface + '.')
make_shirt('s','w')
#8-4
def make_shirt(shirt_size, shirt_typeface = 'I love Python'):
"""说明T shirt的尺寸和字样"""
print('\nThe size of T-shirt is ' + shirt_size + '.')
print('The typeface of the T-shirt is ' + shirt_typeface + '.')
make_shirt('big')
make_shirt('mid')
make_shirt('small','Li')
#8-5 城市
def describe_city(city_name,city_location = 'Iceland'):
print(city_name + 'is in ' + city_location + '.')
describe_city('Reykajvik')
describe_city('Qing dao','China')
describe_city(city_name = 'Chang sha', city_location = 'China')
#8-6城市名
def city_country(city,country):
temporary ='"' + city + ', ' + country + '"'
return temporary.title()
city = city_country('santiago','chile')
print('\n' + city)
city = city_country('da lian','liao ning')
print('\n' + city)
city = city_country('qing dao','shan dong')
print('\n' + city)
#8-7 专辑
def make_album(person_name,album_name,number = ''):
Album = {'person':person_name,'album':album_name}
if number:
Album['number'] = number
return Album
musican = make_album('Wang li hong', 'Zui ai de ren','15')
print(musican)
#8-8 专辑
def make_album(person_name,album_name,number = ''):
Album = {'person':person_name,'album':album_name}
if number:
Album['number'] = number
return Album
while True:
print('\nenter q end the program at any time.')
singer_name = input("Please enter the singer's name: ")
if singer_name == 'q':
break
album_name = input("Please enter the album's name: ")
if album_name == 'q':
break
musican = make_album(singer_name, album_name)
print(musican)
#8-9魔术师
def show_magicians(magicians_names):
for magicians_name in magicians_names:
print('\n' + magicians_name.title())
magicians_names = ['zhang','li','wang','song']
show_magicians(magicians_names)
#8-10了不起的魔术师
def show_magicians(magicians_names):
for magicians_name in magicians_names:
print('\n' + magicians_name.title())
magicians = []
def make_great(magicians_names):
while magicians_names:
magician = 'the Great ' + magicians_names.pop()
magicians.append(magician)
magicians_names = ['zhang','li','wang','song']
make_great(magicians_names)
show_magicians(magicians)
8-11#不变的魔术师
def show_magicians(magicians_names):
for magicians_name in magicians_names:
print('\n' + magicians_name.title())
magicians = []
def make_great(magicians_names):
while magicians_names:
magician = 'the Great ' + magicians_names.pop()
magicians.append(magician)
magicians_names = ['zhang','li','wang','song']
make_great(magicians_names[:])
show_magicians(magicians)
show_magicians(magicians_names)
#8-12 三明治
def adding_ingredients(*toppings):
print('\nThe adding toppings are :')
for topping in toppings:
print('- ' + topping)
adding_ingredients('cheese')
adding_ingredients('meat','egg')
adding_ingredients('meat','egg','cheese')
#8-13用户简介
def build_profile(first, last, **user_informa):
profile = {}
profile['first_name'] = first
profile['last_name'] = last
for k, v in user_informa.items():
profile[k] = v
return profile
user_profile = build_profile('zhang','yong',location = 'guang zhou',sex = 'man',height = 175)
print(user_profile)
#8-14汽车
def make_car(made, type, **other_infor):
information = {}
information['manufacturer'] = made
information['kind'] = type
for k, v in other_infor.items():
information[k] = v
return information
car = make_car('Bmw','truck',color = 'white', fitting = True)
print(car)
Python编程从入门到实践第8章习题答案
最新推荐文章于 2024-03-08 20:31:31 发布