当前位置:   article > 正文

python从入门到实践第8章课后作业_python第八章作业(初级)

python第八章作业(初级)

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)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123

8-15、8-16的函数

#打印名字
def name_print(name):
    """打印名字"""
    print(name)
  • 1
  • 2
  • 3
  • 4
#作业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')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/640746
推荐阅读
相关标签
  

闽ICP备14008679号