【第四周】第八章习题

8-1消息

def desplay_message():
    print ("I am learning function!")
desplay_message()

8-2喜欢的图书

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

8-3T恤

def make_shirt(size ,name):
    print ("The size is:" + size +",and the name is " + name)
make_shirt("XL","I am happy")

8-4大号T恤

def make_shirt(size = 'L' ,name = "I love python"):
    print ("The size is:" + size +",and the name is " + name)
make_shirt(size = 'L')
make_shirt(size = 'M')
make_shirt("XL","I am happy")

8-5城市

def deccribe_city(city = 'Los angelos',nation = 'the USA'):
    print (city + " is in " + nation)
deccribe_city(city = 'New York')
deccribe_city(city = 'Washington')
deccribe_city(city = 'London', nation='the UK')

8-6城市名

def city_country(city ,country):
    name=city + ','+country
    return name
print(city_country('New York','the USA'))
print(city_country('London','the UK'))
print(city_country('Paris','France'))

8-7专辑

def make_album(siname,alname):
    return {'singer':siname , 'album':alname}
print(make_album('Jay','Ye Huimei'))
print(make_album('JJ','New earth'))
print(make_album('Jolin','Beauty Butterfly'))

8-8用户的专辑

def make_album(siname,alname):
    return {'singer':siname , 'album':alname}
while True:
    siname = input ('Please input the name of the singer:')
    if siname == 'q':
        break
    alname = input ('Please input the name of the album:')
    if alname == 'q':
        break
    print (make_album(siname,alname))

8-9魔术师

def show_migicians(magic):
    for name in magic:
        print(name)

magic = ['David' , 'Bob' , 'Kevin']
show_migicians(magic)

8-10了不起的魔术师

def show_migicians(magic):
    for name in magic:
        print(name)
def new(magic):
    lenth = len(magic)
    for i in range(0,lenth):
        magic[i] = 'the great ' + magic [i]
magic = ['David' , 'Bob' , 'Kevin']
new(magic)
show_migicians(magic)

8-11不变的魔术师

def show_migicians(magic):
    for name in magic:
        print(name)
def new(magic):
    lenth = len(magic)
    for i in range(0,lenth):
        magic[i] = 'the great ' + magic [i]
magic = ['David' , 'Bob' , 'Kevin']
magic1 = []
for name in magic:
    magic1.append(name)
new(magic1)
show_migicians(magic)
show_migicians(magic1)

8-12三明治

def sandwich(*thing):
    print('The sandwich was added by ' , thing)
sandwich('beef','pork')
sandwich('vegatable','lettethe')
sandwich('onions','cheese')

8-13用户简介

def build_profile (first,last, **user_info):
    profile  = {}
    profile['first_name']  = first
    profile['last_name'] = last
    for key,value in user_info.items():
        profile[key]=value
    return profile
my_profile = build_profile('Lucy','Zheng',location='Guangzhou',field = 'Computer Science')
print(my_profile)

8-14汽车

def car(producer,ID,**thing):
    acar={}
    acar['producer']=producer
    acar['ID']=ID
    for key,value in thing.items():
        acar[key]= value
    return acar
carfile = car('Bob','10000',owner = 'LucyZheng')
print(carfile)

8-15 打印模型

import print_functions
unprinted_designs = ['iphone case','robot pendat','dodecehedron']
completed_models = print_functions.miao(unprinted_designs)
print ('\nThe following models have been printed:')
for completed_model in completed_models:
    print(completed_model)
#print_functions.py如下:
def miao(unprinted_designs):
    completed_models=[]
    while unprinted_designs:
        current_design = unprinted_designs.pop()
        print('Printing model: ' + current_design)
        completed_models.append(current_design)
    return completed_models

8-16

8-15中的程序中import改为:

from print_functions import miao
from print_functions import  miao as m
from print_functions as prints
from print_functions import *


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值