8-1至8-17

8-1,消息
def display_message():
    print('I studied functions today.')

display_m=essage()

8-2,喜欢的图书
def favorite_book(title):
    print('My favorite books is "' + title + '".')

favorite_book("Alice in Wonderland")

8-3,T恤
def make_shirt(size, word):
    print('This T-shrit is size-' + size + ' with ' + word + ' on it.')

make_shirt('L', 'Hello')
make_shirt(size='X', word='Wrold')

8-4,大号T恤
def make_shirt(size='L', word='I love pyhton'):
    print('This T-shrit is size-' + size + ' with "' + word + '" on it.')

make_shirt(word='Hello')
make_shirt(size='X')
make_shirt()

8-7,专辑
def make_album(singer_name, album_name, amount=-1):
    dist = {'singer_name':singer_name, 'album_name':album_name}
    if amount != -1:
        dist['amount'] = amount
    return dist

album1 = make_album('Lenka', 'We are the brave')
album2 = make_album('Westlife', 'Greatest Hits')
album3 = make_album('Carpenters', '40/40', 40)
album = [album1, album2, album3]

for i in range(3):
    for a, b in album[i].items():
        print(a + ":" + str(b))
    print()

8-10,了不起的魔术师
def show_magicians(magicians):
    for magician in magicians:
        print(magician)

def make_great(magicians):
    for index, magician in enumerate(magicians):
        magicians[index] = magician + " the Great"

magicians = ['xiao ming', 'xiaohong', 'xiao li']

make_great(magicians)
show_magicians(magicians)


8-11,不变的魔术师
def show_magicians(magicians):
    for magician in magicians:
        print(magician)

def make_great(magicians):
    magicians1 = []
    for magician in magicians:
        magicians1.append(magician + " the Great")
    return magicians1

magicians = ['xiao ming', 'xiaohong', 'xiao li']
magicians1 = make_great(magicians[:])

show_magicians(magicians)
show_magicians(magicians1)

8-12,三明治
def sandwiches(*materials):
    print('There are ',end='')
    for material in materials:
        print(material,end=' ')
    print()

sandwiches('cheese', 'eggs', 'ham')
sandwiches('mayonnaise', 'lettuce', 'tomatoes')
sandwiches('bread', 'potatoes', 'beef')

8-14,汽车
def make_info(manufacturer , version, **info):
    car_info = {'manufacturer':manufacturer, 'version':version}
    if info:
        for a, b in info.items():
            car_info[a] = b
    return car_info

car_info = make_info('subaru', 'outback', color='blue', row_package=True)

for a, b in car_info.items():
    print(a + ":" + str(b))

8-16,导入

import hello
hello.hello()
from hello import hello
hello()
from hello import hello as hl
hl()

import hello as hl
hl.hello()

from hello import *
hello()


 


 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值