python从入门到实践第8章课后作业
#作业8-1
# def display_message():
# print('学习了如何定义函数')
# display_message()
# 作业8-2
# def favorate_book(title):
# """显示最喜欢的书"""
# print('One of my favorate books is '+title.title()+'.')
# favorate_book('alice in wonderland')
# 作业8-3
# def make_shirt(size,title):
# print('we need a '+str(size)+' shirt,with '+title.title()+' on it.')
# make_shirt('big','yes')
# make_shirt(size='big',title='yes')
# 作业8-4
# def make_shirt(size='big',title='I love python'):
# print('we need a '+str(size)+' shirt,with '+title.title()+' on it.')
# make_shirt()
# make_shirt(size='middle')
# make_shirt('big','I love java')
# 作业8-5
# def describe_city(city,country='china'):
# print(city.title()+' is in '+country.title()+'.')
# describe_city('beijing')
# describe_city(city='reykjavik',country='iceland')
# describe_city('tiajin','china')
# 作业8-6
# def city_country(city,country):
# discribe='"'+city.title()+','+country.title()+'"'
# return discribe
# a=city_country('beijing','china')
# b=city_country('xian','china')
# c=city_country('santiago','chile')
# print(a+b+c)
# 作业8-7
# def make_album(singer_name,album_name,number=' '):
# p={'singer':singer_name,'album':album_name}
# if number!=' ':
# p['number']=str(number)
# return p
# a=make_album('bbu','iubu',10)
# b=make_album('aaa','mmm')
# c=make_album('bbb','ccc',5)
# print(a)
# print(b)
# print(c)
# 作业8-8
# def make_album(singer_name,album_name,number=' '):
# p={'singer':singer_name,'album':album_name}
# if number!=' ':
# p['number']=str(number)
# return p
# while True:
# print('(enter "q" at any time to quit)')
# a=input("singer:")
# if a=='q':
# break
# b=input('album:')
# if b=='q':
# break
# c=str(input('number:'))
# if c=='q':
# break
#
# d=make_album(singer_name=a,album_name=b,number=c)
# print(d)
# 作业8-9
# def show_magicians(names):
# for name in names:
# print(name)
# show_magicians(['mie','mark','tom','jack'])
# 作业8-10
# def make_graet(names,the_great_names=[]):
# for name in names:
# name='the great '+name
# the_great_names.append(name)
# print(name)
# return the_great_names
# a=make_graet(['mie','mark','tom','jack'])
# print(a)
# 作业8-11
# def make_graet(names,the_great_names=[]):
# for name in names:
# name='the great '+name
# the_great_names.append(name)
# print(name)
# return the_great_names
# list=['mie','mark','tom','jack']
# a=make_graet(list[:])
# print(list)
# print(a)
# 作业8-12
# def make_sandwich(*into):
# """概述要制作的三明治"""
# print('\nmaking a sandwich with the following things:')
# for thing in into:
# print('-'+thing)
# make_sandwich('peperoni')
# make_sandwich('mushrooms','green pepers','extra 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_massage=build_profile('shmise','jucy',location='princeton',
# field='enviroment',like='draw')
# print(my_massage)
# 作业8-14
# def make_car(name,look,**massages):
# """创建一个字典,描述汽车有关信息"""
# car={}
# car['car_name']=name
# car['car_look']=look
# for k,v in massages.items():
# car[k]=v
# return car
# b=make_car('subaru','outback',color='blue',tow_package=True)
# print(b)
8-15、8-16的函数
#打印名字
def name_print(name):
"""打印名字"""
print(name)
#作业8-15
# import printing_functions as pt
# pt.name_print(input('please print a name:'))
# 作业8-16
# import printing_functions
# printing_functions.name_print('good')
# from printing_functions import name_print
# name_print('great')
# from printing_functions import name_print as np
# np('very good')
# import printing_functions as pf
# pf.name_print('love')
# from printing_functions import *
# printing_functions.name_print('like')