我是靠谱客的博主 怕孤独学姐,最近开发中收集的这篇文章主要介绍《Python编程:从入门到实践》课后习题-第3章3-1 姓名3-2 问候语3-3 自己的列表3-4 嘉宾名单3-5 修改嘉宾名单3-6 添加嘉宾3-7 缩减名单3-8 放眼世界3-9 晚餐嘉宾,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
3-1 姓名
#3-1 姓名
names = ['Eric','Rose','Jack','Cristina']
for name in names:
print name
3-2 问候语
#3-2 问候语
names = ['Eric','Rose','Jack','Cristina']
for name in names:
print(name + ", Welcome to China.")
3-3 自己的列表
#3-3 自己的列表
ways = ['bicycle','car','subway']
for way in ways:
print("I would like to go home by " + way)
3-4 嘉宾名单
#3-4 嘉宾名单
names = ['Eric','Amber','Britney','Cristina']
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
3-5 修改嘉宾名单
#3-5 修改嘉宾名单
names = ['Eric','Amber','Britney','Cristina']
for name in names:
print (name + " 欢迎你来和我共进晚餐!")
print("n")
print(names[2] + "有事无法赴约。")
names[2] = 'Gina'
for name in names:
print (name + " 欢迎你来和我共进晚餐!")
3-6 添加嘉宾
#3-6 添加嘉宾
names = ['Eric','Amber','Britney','Cristina']
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
print"n"
print(names[2] + "有事无法赴约。")
names[2] = 'Gina'
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
print"n"
print"我找到一张更大的餐桌!"
names.insert(0,'Monica')
names.insert(2,'Bruce')
names.append('Lisa')
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
3-7 缩减名单
#3-7 缩减名单
names = ['Eric','Amber','Britney','Cristina']
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
print"n"
print(names[2] + "有事无法赴约。")
names[2] = 'Gina'
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
print"n"
print"我找到一张更大的餐桌!"
names.insert(0,'Monica')
names.insert(2,'Bruce')
names.append('Lisa')
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
print"n非常抱歉,我只能邀请两位嘉宾"
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
del names[0]
del names[0]
print names
3-8 放眼世界
#3-8 放眼世界
travel_list = ['Los Angeles','Australia','Korea','Japan','Paris']
print travel_list
print sorted(travel_list)
print travel_list
print sorted(travel_list,reverse = True)
print travel_list
print"n"
travel_list.reverse()
print travel_list
travel_list.reverse()
print travel_list
travel_list.sort()
print travel_list
travel_list.sort(reverse = True)
print travel_list
3-9 晚餐嘉宾
#3-9 晚餐嘉宾
names = ['Eric','Amber','Britney','Cristina']
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
length = str(len(names))
print("共邀请了" + length + "位共进晚餐!n")
print(names[2] + "有事无法赴约。")
names[2] = 'Gina'
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
length = str(len(names))
print("共邀请了" + length + "位共进晚餐!n")
print"我找到一张更大的餐桌!"
names.insert(0,'Monica')
names.insert(2,'Bruce')
names.append('Lisa')
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
length = str(len(names))
print("共邀请了" + length + "位共进晚餐!n")
print"非常抱歉,我只能邀请两位嘉宾"
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
list_delete = names.pop()
print(list_delete + " 非常抱歉,无法邀请你来共进晚餐。")
for name in names:
print(name + " 欢迎你来和我共进晚餐!")
del names[0]
del names[0]
print names
length = str(len(names))
print("共邀请了" + length + "位共进晚餐!")
最后
以上就是怕孤独学姐为你收集整理的《Python编程:从入门到实践》课后习题-第3章3-1 姓名3-2 问候语3-3 自己的列表3-4 嘉宾名单3-5 修改嘉宾名单3-6 添加嘉宾3-7 缩减名单3-8 放眼世界3-9 晚餐嘉宾的全部内容,希望文章能够帮你解决《Python编程:从入门到实践》课后习题-第3章3-1 姓名3-2 问候语3-3 自己的列表3-4 嘉宾名单3-5 修改嘉宾名单3-6 添加嘉宾3-7 缩减名单3-8 放眼世界3-9 晚餐嘉宾所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复