第四周作业(周三)
2018-03-29 16:13
211 查看
第8章作业
习题8-2
def favorite_book(title): print("My favorite book is " + title) favorite_book("Alice in Wonderland")
My favorite book is Alice in Wonderland
习题8-4
def make_shirt(sentense = "I love python", size = "Large"): print("This is a " + size + " shirt, with " + sentense) make_shirt() make_shirt(size = "Medium") make_shirt(sentense = "I love lily")
This is a Large shirt, with I love python This is a Medium shirt, with I love python This is a Large shirt, with I love lily
习题8-6
def city_country(city, country): return city + ", " + country print(city_country("Guangzhou", "China")) print(city_country("Shenzhen", "China")) print(city_country("Beijing", "China"))
Guangzhou, China Shenzhen, China Beijing, China
习题8-14
def make_car(manu, model, **args): ret = {} ret['manu'] = manu ret['model'] = model for (k, v) in args.items(): ret[k] = v return ret print(make_car('subaru', 'outback', color='blue', tow_package=True))
{'manu': 'subaru', 'model': 'outback', 'color': 'blue', 'tow_package': True}