Python编程:从入门到实践(课后习题8)
来源:互联网 发布:ep软件 编辑:程序博客网 时间:2024/05/17 23:55
# 8-1 消息def display_message():print("This chapter I will learning function.")display_message()# 8-2 喜欢的图书def favorite_book(title):print("One of my favorite books is " + title + ".")favorite_book('Python for Data Analysis')# 8-3 T恤def make_shirt(size, word):print("T-shirt's size is: " + str(size) + '.')print("T-shirt's word is: " + str(word) + '.')make_shirt(L, 24)make_shirt(word='I love you', size='M')# 8-4 大号T恤def make_shirt(size='大号', word='I love Python.'):print("T-shirt's size is: " + str(size) + '.')print("T-shirt's word is: " + str(word) + '.')make_shirt()make_shirt(size='中号')make_shirt(size='加大号', word="I don't care")# 8-5 城市def describe_city(city, nation='China'):print("City: " + city)print("Nation: " + nation)describe_city('Guangzhou')describe_city('Beijing')describe_city('Los angels', nation='America')# 8-6 城市名def city_country(city, nation):x = city + ', ' + nationreturn xcity_nation1 = city_country('Guangzhou', 'China')city_nation2 = city_country('Tokyo', 'Japan')city_nation3 = city_country('Seoul', 'Korea')print(city_nation1)print(city_nation2)print(city_nation3)# 8-7 专辑def make_album(singer, album, num=''):albums = {}if num:albums['singer'] = singeralbums['album'] = albumalbums['num'] = numelse:albums['singer'] = singeralbums['album'] = albumreturn albumsu87 = make_album('陈奕迅', 'U87')u87_num = make_album('陈奕迅', 'U87', num=12)happy = make_album('陈奕迅', '我的快乐时代', num=15)print(u87)print(u87_num)print(happy)# 8-8 用户的专辑album_active = Truewhile album_active:singer = input("Singer: ")album = input("Album: ")num = input("Number: ")you_album = make_album(singer, album, num)print(you_album)quit = input("Continue or quit? (y/n) ")if quit == 'n':album_active = False# 8-9 魔术师magician = ['criss', 'jason', 'cyril']def show_magicians(magician_list):for magician in magician_list:print(magician.title())show_magicians(magician)# 8-10 了不起的魔术师def make_great(magician_list):for i in range(3):magician_list[i] = 'the Great ' + magician_list[i]return magician_list # 差点忘记return了make_great(magician)show_magicians(magician)# 8-11 不变的魔术师magician_great = make_great(magician[:])show_magicians(magician)show_magicians(magician_great)# 8-12 三明治def sandwich(*args):for i in args:print(i)# 8-13 用户简介def build_profile(first, last, **user_info):profile = {}profile['first_name'] = firstprofile['last_name'] = lastfor key, value in user_info.items():profile[key] = valuereturn profilemy_profile = build_profile('Zhou', 'Kai', user_info={'age': 26, 'hobby': 'basketball', 'lover': 'Zhanglili'})print(my_profile)# 8-14 汽车def car_information(maker, type1, **kw):information = {}information['maker'] = makerinformation['type'] = type1for i, j in kw.items():information[i] = jreturn information
阅读全文
0 0
- Python编程:从入门到实践(课后习题8)
- Python编程:从入门到实践(课后习题3)
- Python编程:从入门到实践(课后习题4)
- Python编程:从入门到实践(课后习题5)
- Python编程:从入门到实践(课后习题6)
- Python编程:从入门到实践(课后习题7)
- Python编程:从入门到实践(课后习题9)
- Python编程:从入门到实践(课后习题11)
- Python编程:从入门到实践(课后习题10)
- Python 从入门到实践 5-8 课后习题
- Python 从入门到实践 7-8 课后习题
- Python 从入门到实践 8-1 课后习题
- Python 从入门到实践 8-3 课后习题
- Python 从入门到实践 8-6 课后习题
- Python 从入门到实践 8-9 课后习题
- Python 从入门到实践 8-12 课后习题
- Python 从入门到实践 5-1 课后习题
- Python 从入门到实践 5-3 课后习题
- 【安全牛学习笔记】MANAGEMENT FRAME 管理帧
- 一个薅羊毛解决的框架,因为内存占用太大,没实验。。
- vue+webpack项目创建过程
- 使用碰撞指针解决LeetCode问题:SortColor75,TwoSumII167,ReverseString344,reverseVowels345
- 排列组合
- Python编程:从入门到实践(课后习题8)
- 内部类与外部类之间访问总结
- 测试模型之W模型
- 【错误】关于DateTable中 Cannot reinitialise DataTable问题
- 设计模式学习-简单工厂模式
- 编译
- python Tkinter学习
- SGISTL源码探究-关联式容器:hash_multimap
- elasticsearch 5.1 java开发用例