作业七2018.4.1

8-1

def display_message():
    print('We learn about function in this chapter')
display_message()

输出:

We learn about function in this chapter

8-2

def favorite_book(title):
    print('One of my favorite book is '+title)
favorite_book('Alice in Wonderland')

输入:

Alice in Wonderland

输出:

One of my favorite book is Alice in Wonderland

8-3

def make_shirt(size,name='I love Python'):
    print('We make a '+size+' shirt print with '+name)
make_shirt('large')
make_shirt('middle')
make_shirt('middle','I hate C++')

输出:

We make a large shirt print with I love Python
We make a middle shirt print with I love Python
We make a middle shirt print with I hate C++

8-5

def describe_city(city,country='China'):
    print(city+' is in '+country)

describe_city('Guangzhou')
describe_city('Shanghai')
describe_city('New York','America')

输出:

Guangzhou is in China
Shanghai is in China
New York is in America

8-7

def make_album(names,albums,numbers=['','','']):
    for number in numbers:
        if number:
            album_one={'name':names.pop(),'album_name':albums.pop(),'number':number}
        else:
            album_one={'name':names.pop(),'album_name':albums.pop()}
        print(album_one)
names=['Mike','Tina','Tom']
album=['sky','love','black']
numbers=['','3','4']
make_album(names,album,numbers)

输出:

{'name': 'Tom', 'album_name': 'black'}
{'name': 'Tina', 'album_name': 'love', 'number': '3'}
{'name': 'Mike', 'album_name': 'sky', 'number': '4'}

8-12

def make_sandwish(*adds):
    print('You want ',end='')
    for add in adds:
        print(add+' ',end='')
    print()
make_sandwish('cheese','beef')
make_sandwish('beef')
make_sandwish('ham','chicken','cheese')

输出:

You want cheese beef 
You want beef 
You want ham chicken cheese 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值