《Python编程——从入门到实践》第八章部分习题解

# 8-2
def favorite_book(title):
	print('One of my favorite book is ' + title)
title_temp = input("What's your favorite book?")
favorite_book(title_temp)

# 8-5
def describe_city(city,country='China'):
	print(city + ' is in ' + country)
describe_city('Shanghai')
describe_city('Beijing')
describe_city('New York','USA')

# 8-7
def make_album(name,album):
	albums = {name : album}
	return albums
album_temp = make_album('Alice','1')
print(album_temp)
album_temp = make_album('Bob','2')
print(album_temp)
album_temp = make_album('Carol','3')
print(album_temp)

# 8-9
magicians = ['Alice' , 'Bob' , 'Carol']
def show_magicians(magicians):
	for magician in magicians:
		print(magician)
show_magicians(magicians)

# 8-14
def make_car(productor,versions,**msg):
	cars = {}
	cars['productor'] = productor
	cars['versions'] = versions
	for key,value in msg.items():
		cars[key] = value
	return cars
car = make_car('subaru', 'outbreak', color='blue', tow_package=True)
print(car)

# 8-16
hello_world.py
def print_hello_world():
	print('Hello world.')

import.py
import hello_world
hello_world.print_hello_world()
from hello_world import print_hello_world
print_hello_world()
from hello_world import print_hello_world as phw
phw()
import hello_world as hw
hw.print_hello_world()
from hello_world import *
print_hello_world()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值