Python编程从入门到实践第8章习题答案

#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)


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值