8-2 喜欢的图书
代码:
def favorite_book(book): print("One of my favorite books is " + book) favorite_book("《灿烂千阳》")
结果:
One of my favorite books is 《灿烂千阳》
8-4 大号t恤
代码:
def make_shirt(message="I love python", size="大号"): print("一件印有" + message + "的" + size + "T恤") make_shirt() make_shirt(size = "中号", message = "hell, world")
结果:
一件印有I love python的大号T恤
一件印有hell, world的中号T恤
8-6 城市名
代码:
def city_country(name, belong): return name + ", " + belong print(city_country("Beijing", "China"))
结果:
Beijing, China
8-11 了不起的魔术师
代码:
def show_magicians(list): print(list) def make_great(list): for i in range(len(list)): list[i] = "the Great " + list[i] return list list = ["Zhang", "Li", "Wang"] show_magicians(list) list_made = make_great(list[:]) show_magicians(list) show_magicians(list_made)
结果:
['Zhang', 'Li', 'Wang']
['Zhang', 'Li', 'Wang']
['the Great Zhang', 'the Great Li', 'the Great Wang']
8-12 三明治
代码:
def make_sandwich(*list): print("你所要的三明治包含:") print(list) make_sandwich("鸡蛋", "火腿") make_sandwich("海苔", "肉松", "鸡蛋") make_sandwich("鸡排", "生菜", "沙拉酱", "芥末酱")
结果:
你所要的三明治包含:
('鸡蛋', '火腿')
你所要的三明治包含:
('海苔', '肉松', '鸡蛋')
你所要的三明治包含:
('鸡排', '生菜', '沙拉酱', '芥末酱')