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

《Python编程 从入门到实践》第3章动手试一试答案

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

《Python编程 从入门到实践》第3章动手试一试答案

第三章
#3-1 姓名
names = ['trek', 'cannondale', 'redline', 'specialized']
for name in names:
    print(name)
#3-2 问候语
names = ['trek', 'cannondale', 'redline', 'specialized']
for name in names:
    print('Hello '+name+" good morning!")
#3-3 自己的列表
names = ['car', 'bicycle', 'bus']
for name in names:
    print('my favorite vehicle is ' + name + '.')
#3-4 嘉宾名单
persons = ["唐僧","孙悟空","猪八戒"]
for person in persons:
    print('您好 '+person+' ,我想请你吃饭!')
#3-5 修改嘉宾名单
print('Sorry the '+persons[1]+' has no time these days ,please call someone else.')
persons[1]='白骨精'
for person in persons:
    print('您好 '+person+' ,我想请你吃饭!')
#3-6 添加嘉宾
print('My lovely friends ,i have find a bigger desk and now we can invite more friends')
print(persons)
persons.insert(0,'牛魔王')
persons.insert(2,'如来')
persons.append('沙悟净')
print(persons)
for person in persons:
    print('您好 '+person+' ,我想请你吃饭!')
#3-7 缩减名单
print('Oh my God ,now i have to pick two of you!')
for index in range(2,len(persons)):
    pop_person=persons.pop()
    print("sorry "+pop_person+" i can't help it ,because the book says.")
for person in persons:
    print('Dear '+person+ ' everything went according to plan.')
del persons[-1]
del persons[0]
print(persons)
#3-8 放眼世界
place = ['beijing','shandong','yunnan','qingdao','hangzhou']
print(place)
print(sorted(place))
print(place)
print(sorted(place,reverse=True))
print(place)
place.reverse()
print(place)
place.reverse()
print(place)
place.sort()
print(place)
place.sort(reverse=True)
print(place)
#3-9 晚餐嘉宾
persons = ["唐僧","孙悟空","猪八戒"]
for person in persons:
    print('您好 '+person+' ,我想请你吃饭!')

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

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

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