栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python编程:从入门到实践 练习答案 chapter03

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python编程:从入门到实践 练习答案 chapter03

## CHAPTER 03
3-1
names = ['L','H','L','W']
print(names[0])
print(names[1])
print(names[2])
print(names[3])


3-2
names = ['L','H','L','W']
print('Hello ' + names[0])
print('Hello ' + names[1])
print('Hello ' + names[2])
print('Hello ' + names[3])


3-3
communication = ['walk','bicycle','subway','taxi','automobile']
print('I would like own a ' +  communication[2].title())


3-4
guests = ['c','s','j']
msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)


3-5
guests = ['c','s','j']

msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)

print('n' + guests[1] + " just can't come" + 'n')
guests.remove('s')
guests.insert(1,'w')

msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)


3-6
guests = ['c','s','j']

msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)

print('n' + guests[1] + " just can't comen")
guests.remove('s')
guests.insert(1,'w')

msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)

print('nI have found a bigger tablen')

guests.insert(0,'l')
guests.insert(2,'y')
guests.append('s')

msg = 'come to dinner ' + guests[0] + 'ncome to dinner ' + guests[1] + 'ncome to dinner ' + guests[2] + 'ncome to dinner ' + guests[3] + 'ncome to dinner ' + guests[4] + 'ncome to dinner ' + guests[5]
print(msg)


3-7
guests = ['c','s','j']

msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)

print('n' + guests[1] + " just can't comen")
guests.remove('s')
guests.insert(1,'w')

msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)

print('nI have found a bigger tablen')

guests.insert(0,'l')
guests.insert(2,'y')
guests.append('s')

msg = 'come to dinner ' + guests[0] + 'ncome to dinner ' + guests[1] + 'ncome to dinner ' + guests[2] + 'ncome to dinner ' + guests[3] + 'ncome to dinner ' + guests[4] + 'ncome to dinner ' + guests[5]
print(msg)


print('nnthe table can not reach in time')
print(guests.pop() + ', u r rejected')
print(guests.pop() + ', u r rejected')
print(guests.pop() + ', u r rejected')
print(guests.pop() + ', u r rejected')

print('n' + guests[0] + ', u r still fucking invited')
print(guests[1] + ', u r still fucking invited')

del guests[0]
del guests[0]
print(guests)


3-8
wonderlands = ['singapore','london','berlin','lasa','san francisco']
print(wonderlands)

print('nsorted')
print(sorted(wonderlands))
print(wonderlands)

print('nsorted() + reversed')
print(sorted(wonderlands, reverse=True))
print(wonderlands)

print('nreserved()')
wonderlands.reverse()
print(wonderlands)

print('nreversed+1')
wonderlands.reverse()
print(wonderlands)

print('nsort()')
wonderlands.sort()
print(wonderlands)

print('nsort(reverse=True)')
wonderlands.sort(reverse=True)
print(wonderlands)


3-9
guests = ['c','s','j']
msg = 'come to dinner ' + guests[0]
print(msg)

msg = 'come to party ' + guests[1]
print(msg)

msg = 'come to party ' + guests[2]
print(msg)

print(len(guests))


3-10
...


3-11
...


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/357497.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号