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-1至8-17_第1张图片

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-1至8-17_第2张图片
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-1至8-17_第3张图片
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-1至8-17_第4张图片
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-1至8-17_第5张图片
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()


 
  


 
  


你可能感兴趣的:(8-1至8-17)