[SYSU][大二下] 高级编程技术HW Week-4 Lecture-2

Question

教材中课后的练习,8-1到8-17,选一些写到你的博客上


Answer

''' 
SYSU - [专选]高级编程技术 - Week4, Lecture2 HW    
by Duan    
2018.03.28   
'''    

'''
8-1 消息
'''
def display_message():
    """打印一个句子,指出本章的学习内容"""
    print("I've learned how to build a function.")
display_message()
#Output:
# I've learned how to build a function.


'''
8-3 T恤
'''
def make_shirt(size, others):
    """接受一个尺码以及要印到T恤上的字样,打印一个句子"""
    print("We'll make a T-shirt painted 'Hello world!' of size", size + '.')
make_shirt(size = 'M', others = 'Hello world!')
#Output:
# We'll make a T-shirt painted 'Hello world!' of size M.


'''
8-5 城市
'''
def describe_city(city, nation = 'China'):
    print(city.title(), 'is in', nation.title() + '.')
cities = {'Shanghai': 'China', 'Wuhan': 'China', 'Tokyo': 'Japan'}
for city, nation in cities.items():
    describe_city(city, nation)
#Output:
# Shanghai is in China.
# Wuhan is in China.
# Tokyo is in Japan.


'''
8-7 专辑
'''
def make_album(singer, album, num_of_song = ''):
    if num_of_song:
        description = {'Album name': album, 'Singer': singer, 'Song Number': num_of_song}
    else:
        description = {'Album name': album, 'Singer': singer}
    return description
print(make_album('Nirvana', 'MTV unplugged In New York', 14))
print(make_album('illion', 'P.Y.L'))
print(make_album('Douwei', 'Yuxu', 12))
#Output:
# {'Album name': 'MTV unplugged In New York', 'Singer': 'Nirvana', 'Song Number': 14}
# {'Album name': 'P.Y.L', 'Singer': 'illion'}
# {'Album name': 'Yuxu', 'Singer': 'Douwei', 'Song Number': 12}


'''
8-11 不变的魔术师
'''
def show_magicians(magicians):
    for magician in magicians:
        print(magician)
def make_great(magicians):
    for i in range(0, len(magicians)):
        magicians[i] = 'the Great ' + magicians[i]
    return magicians
magicians = ['Steven Frayne', 'Franz Harary', 'Jason Latimer']
changed_magicians = make_great(magicians[:])
show_magicians(magicians)
show_magicians(changed_magicians)
#Output:
# Steven Frayne
# Franz Harary
# Jason Latimer
# the Great Steven Frayne
# the Great Franz Harary
# the Great Jason Latimer


'''
8-14 汽车
'''
def make_car(manufacturer, model, **car_info):
    car = {}
    car['manufacturer'] = manufacturer
    car['model'] = model
    for key, value in car_info.items():
        car[key] = value
    return car
car = make_car('subaru', 'outback', color = 'blue', tow_package = True)
print(car)
#Output:
# {'manufacturer': 'subaru', 'model': 'outback', 'color': 'blue', 'tow_package': True}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值