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

时间:2019-02-20
本文章向大家介绍Python编程从入门到实践第8章习题答案,主要包括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)