Weak4 Chapter8 Homework

8-2 喜欢的图书

def favourite_book(title):
    print("One of my favourite books is "+title)
favourite_book("Alice in Wonderland")

输出结果是:

One of my favourite books is Alice in Wonderland

8-3,8-4 T恤

def make_shirt(size = '大号',message = 'Python'):
    print('制作一件印有字样"I love '+message+'"的'+size+' T-shirt')
make_shirt()
make_shirt("中号")
make_shirt(message="C++",size="小号")

输出结果是:

制作一件印有字样"I love Python"的大号T-shirt
制作一件印有字样"I love Python"的中号T-shirt
制作一件印有字样"I love C++"的小号T-shirt

8-6 城市名

def city_country(city,country):
    return '"'+city.title()+', '+country.title()+'"'
print(city_country("santiago","chile"))
print(city_country("moscow","russia"))
print(city_country("Washington D.C.","america"))

输出结果是:

"Santiago, Chile"
"Moscow, Russia"
"Washington D.C., America"

8-9,8-10 伟大的魔术师

def show_magicians(lists):
    print(lists)
def make_great(lists):
    for i in range(len(lists)):
        lists[i] = "the Great "+lists[i]

list = ["Dynamo","Jason Latimer","刘谦"]
show_magicians(list)
make_great(list)
show_magicians(list)

输出结果是:

['Dynamo', 'Jason Latimer', '刘谦']
['the Great Dynamo', 'the Great Jason Latimer', 'the Great 刘谦']

8-11 不变的魔术师

def show_magicians(lists):
    print(lists)
def make_great(lists):
    for i in range(len(lists)):
        lists[i] = "the Great "+lists[i]
    show_magicians(lists)

list = ["Dynamo","Jason Latimer","刘谦"]
show_magicians(list)
make_great(list[:])
show_magicians(list)

输出结果是:

['Dynamo', 'Jason Latimer', '刘谦']
['the Great Dynamo', 'the Great Jason Latimer', 'the Great 刘谦']
['Dynamo', 'Jason Latimer', '刘谦']

8-14 汽车

def make_car (manufacturer,model,**other):
    profile = {}
    profile['manufacturer']=manufacturer
    profile['model']=model
    for k,v in other.items():
        profile[k]=v
    return profile
car = make_car('saburu','outbreak',color = 'blue',tow_package = True)
print(car)

输出结果是:

{'manufacturer': 'saburu', 'model': 'outbreak', 
'color': 'blue', 'tow_package': True}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值