《Python程式設計》第八章部分課後練習題
#8-4 大號T恤:
程式碼:
#8-4 大號T恤
def make_shirt(size='L', style='I love Python'):
"""pass two argurments to make the specific T-shirt"""
message = "This T-shirt's size is " + size + '\n'
message += "This T-shirt's style is " + style + '\n'
print(message)
make_shirt()
make_shirt('M')
make_shirt(style='I hate Python')
輸出:
This T-shirt's size is L
This T-shirt's style is I love Python
This T-shirt's size is M
This T-shirt's style is I love Python
This T-shirt's size is L
This T-shirt's style is I hate Python
#8-5 城市:
程式碼:
#8-5 城市
def describe_city(city, country='Iceland'):
"""print the city belongs to which counrty"""
message = city + ' is in ' + country + '.'
print(message)
describe_city('Reykjavík')
describe_city('Kópavogur')
describe_city('New york')
輸出:
Reykjavík is in Iceland.
Kópavogur is in Iceland.
New york is in Iceland.
#8-6 城市名:
程式碼:
#8-6 城市名
def city_country(*item):
"""pass (city, country), then print the message of city_country"""
for pair in item:
message = pair[0] + ', ' + pair[-1]
print(message)
city_country(('Ottawa', 'Canada'), ('Beijing', 'China'), ('Cairo', 'Egypt'), ('Moscow', 'Russia'))
輸出:
Ottawa, Canada
Beijing, China
Cairo, Egypt
Moscow, Russia
#8-7 專輯:
程式碼:
#8-7 專輯
def make_album(singer_name, album_name, songs_num=''):
"""receive singer's name and album's name of a album, then return the dictionary"""
album = {'singer_name': singer_name, 'album_name': album_name}
if songs_num:
album['songs_num'] = songs_num
return album
print(make_album('Eason', 'A life'))
print(make_album('Jay', 'fantacy', 10))
輸出:
{'singer_name': 'Eason', 'album_name': 'A life'}
{'singer_name': 'Jay', 'album_name': 'fantacy', 'songs_num': 10}
#8-14 汽車:
程式碼:
#8-14 汽車
def make_car(manufacturer, model_type, **others):
"""return all information of a Car"""
car = {'manufacturer': manufacturer, 'model_type': model_type}
for key, value in others.items():
car[key] = value
return car
car = make_car('subaru', 'outback', color='blue', tow_package=True)
print(car)
car = make_car('Toyta', 'AE86', color='red')
print(car)
輸出:
{'manufacturer': 'subaru', 'model_type': 'outback', 'color': 'blue', 'tow_package': True}
{'manufacturer': 'Toyta', 'model_type': 'AE86', 'color': 'red'}
相關文章
- 《Python程式設計》第七章部分課後練習題Python程式設計
- 《Python程式設計》第十一章部分課後練習題Python程式設計
- 《Python程式設計》第九章部分課後練習題Python程式設計
- 《Python程式設計》第十章部分課後練習題Python程式設計
- Python 程式設計練習Python程式設計
- Python快速程式設計入門課後程式題答案Python程式設計
- python課後習題Python
- C與指標課後練習與程式設計答案(不斷更新)指標程式設計
- 程式設計假期練習題--1程式設計
- 程式設計假期練習題--2程式設計
- 程式設計假期練習題--3程式設計
- Java語言程式設計與資料結構(基礎篇)課後複習題 第八章(四)Java程式設計資料結構
- Python 小甲魚教程 課後練習42Python
- 慕課網Python入門練習題---Python
- C與指標課後答案與程式設計練習(第一章)指標程式設計
- 程式設計練習程式設計
- 《Python程式設計練習與解答》之程式設計概論Python程式設計
- C primer plus 第六版 第八章 第四題 程式設計練習答案程式設計
- C primer plus 第六版 第八章 第五題 程式設計練習答案程式設計
- C primer plus 第六版 第八章 第六題 程式設計練習答案程式設計
- C primer plus 第六版 第八章 第七題 程式設計練習答案程式設計
- C primer plus 第六版 第八章 第八題 程式設計練習答案程式設計
- Python程式設計基礎練習——撲克牌發牌問題Python程式設計
- 《Java語言程式設計(基礎篇)(原書第10版)》第2~4章部分程式設計練習題程式碼Java程式設計
- 大一C語言程式設計練習題C語言程式設計
- 50道Java基礎程式設計練習題Java程式設計
- 一些簡單的程式設計練習題程式設計
- 新手練習:Python練習題目Python
- Python 練習題Python
- 零基礎學習Python__小甲魚第一課筆記與課後練習Python筆記
- 演算法導論課後習題解答 第一部分 練習1.1-1->1.1-5演算法
- 與小卡特一起學python 第1章 出發吧 課後練習題Python
- 好程式設計師web前端分享前端 javascript 練習題程式設計師Web前端JavaScript
- 好程式設計師web前端教程分享javascript 練習題程式設計師Web前端JavaScript
- 華南農業大學C語言程式設計課後習題(第六章)C語言程式設計
- 第二週程式設計練習程式設計
- 溫度轉換——MOOC《Python語言程式設計》第1周練習題2Python程式設計
- java課後題複習Java