py第八章习题

#8-1
def display_message():
	print('Function!!!')
display_message()
display_message()
display_message()

#8-2
def favorite_book(title):
	print(title + ' is my favourite book!!')
favorite_book('Dark')
favorite_book('Fantasy')
#8-3
def make_shirt(size, word):
	print('Shirt`s size is: ' + str(size) + ', and "' + word + '" will be print on the shirt.')
make_shirt(100,'fantasy')
#8-4
def make_shirt(size, word = 'I love Python'):
	print('Shirt`s size is: ' + str(size) + ', and "' + word + '" will be print on the shirt.')
make_shirt(50)
make_shirt(100)
make_shirt(100,'fantasy')


#8-5
def describe_city(city, country = 'China'):
	print(city.title() + ' is in '+ country.title() + '.')
describe_city('Shanghai')
describe_city('Beijing')
describe_city('Tokyo','Japan')
	

#8-6
def city_country(city, country):
	re = '"' + city.title() + ', ' + country.title() + '"'
	return re
print (city_country('Sahanghai','China'))
print (city_country('Santiago','chile'))
print (city_country('Tokyo','Japan') )
	

#8-7
def make_album(singer,alb,sings = 0):
	re = {
		'name': singer,
		'album': alb,
		}
	if sings > 0:
		re['amount'] = sings
	return re
print( make_album('n1','a1'))
print( make_album('n2','a2'))
print( make_album('hello','hjaa',20))

	

#8-8
def make_album(singer,alb,sings = 0):
	re = {
		'name': singer,
		'album': alb,
		}
	if sings > 0:
		re['amount'] = sings
	return re
	
while True:
	name = input('Input the singer`s name: ')
	album = input('Input his album `s name: ')
	print(make_album(name,album))
	q = input('Do you want toi add one more item?(y/n)')
	if q == 'n':
		break

#8-9
def show_magicans(magicans):
	for magican in magicans:
		print(magican)
		
magicans = ['Ti','Ben','Ann']
show_magicans(magicans)

#8-10
def show_magicans(magicans):
	for magican in magicans:
		print(magican)
		
def make_great(magicans):
	l = len(magicans)
	for i in range(l):
		magicans[i] = 'the Great ' + magicans[i]
	
magicans = ['Ti','Ben','Ann']
make_great(magicans)
show_magicans(magicans)
#8-11
def show_magicans(magicans):
	for magican in magicans:
		print(magican)
		
def make_great(magicans):
	l = []
	while magicans:
		current = magicans.pop()
		l.append('the Great ' + current)
	return l
	
magicans = ['Ti','Ben','Ann']
show_magicans(make_great(magicans[:]))
show_magicans(magicans)

#8-12
def add(*foods):
	print('Your sandwich include: ')
	for food in foods:
		print(food)
add('1','2','3')
add('tomato','potato')
add('chcken')

#8-14
def make_car(maker, typ, **other):
	car = {}
	car['maker'] = maker
	car['type'] = typ
	for key,val in other.items():
		car[key] = val
	return car
car = make_car('subaru','outback',color = 'blue', tow_package=True)
print(car)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值