【第二周】第三章全部习题3-1~3-11
2018-03-12 22:42
316 查看
3-1姓名names = ['LucyZheng','JairZhu','HHL','WilliamZheng']
for name in names:
print (name)
3-2问候语
for tran in trans:
print("I would like to own " + tran)3-4嘉宾名单names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")3-5修改嘉宾名单names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
3-6添加嘉宾names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oh!I have found a bigger table!")
names.insert(0,'Manman') #插入元素
names.insert(2,'Miracle')
names.append('Wonder')
for name in names:
print (name + " ,would you like to have a dinner with me?")3-7缩减名单names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oh!I have found a bigger table!")
names.insert(0,'Manman') #插入元素
names.insert(2,'Miracle')
names.append('Wonder')
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! I only have to invite 2 friends!")
length=len(names)
while length > 2: #判断是否删除到只剩下两位嘉宾
length-=1
print(names[length] + " ,I am so sorry!")
names.pop(-1)
for name in names: #输出两位嘉宾的信息
print(name + " ,I'm looking forward to your visit.")
del names[0]
del names[0] #删除最后两位嘉宾3-8放眼世界cities=['Paris','Chengdu','Mosco','London','Beijing']
print(cities)
print(sorted(cities)) #按字母顺序排序输出,不改变原值
print(cities)
print(sorted(cities,reverse = True)) #按字母反向排序,不改变原值
print(cities)
cities.reverse() #倒序输出
print(cities)
cities.reverse() #再倒序输出
print(cities)
sorted(cities) #按字母顺序排序修改
print(cities)
sorted(cities,reverse=True) #按字母顺序倒序排序修改
print(cities)3-9晚餐嘉宾names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
print(len(names))3-10尝试使用各个函数cities=['Paris','Chengdu','Mosco','London','Beijing']
cities.append('Shanghai') #尾部添加
print(cities)
cities.insert(0,'Guangzhou') #中间插入
print(cities)
del cities[3] #删除
print(cities)
cities.pop(-1) #特定位置删除
print(cities)
cities.remove('Beijing') #根据值删除
print(cities)
cities.sort() #排序
print(cities)
cities.reverse() #倒序排列
print(cities)
print(len(cities)) #输出列表长度
3-11有意引发错误,使操作一个越界的值即可。
有意触发:names=[]
print(names[-1])
修改:names=['Haha']
print(names[-1])
for name in names:
print (name)
3-2问候语
names = ['LucyZheng','JairZhu','HHL','WilliamZheng'] for name in names: print (name + ",nice to meet you!")3-3自己的列表trans = ['train','bike','car']
for tran in trans:
print("I would like to own " + tran)3-4嘉宾名单names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")3-5修改嘉宾名单names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
3-6添加嘉宾names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oh!I have found a bigger table!")
names.insert(0,'Manman') #插入元素
names.insert(2,'Miracle')
names.append('Wonder')
for name in names:
print (name + " ,would you like to have a dinner with me?")3-7缩减名单names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oh!I have found a bigger table!")
names.insert(0,'Manman') #插入元素
names.insert(2,'Miracle')
names.append('Wonder')
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! I only have to invite 2 friends!")
length=len(names)
while length > 2: #判断是否删除到只剩下两位嘉宾
length-=1
print(names[length] + " ,I am so sorry!")
names.pop(-1)
for name in names: #输出两位嘉宾的信息
print(name + " ,I'm looking forward to your visit.")
del names[0]
del names[0] #删除最后两位嘉宾3-8放眼世界cities=['Paris','Chengdu','Mosco','London','Beijing']
print(cities)
print(sorted(cities)) #按字母顺序排序输出,不改变原值
print(cities)
print(sorted(cities,reverse = True)) #按字母反向排序,不改变原值
print(cities)
cities.reverse() #倒序输出
print(cities)
cities.reverse() #再倒序输出
print(cities)
sorted(cities) #按字母顺序排序修改
print(cities)
sorted(cities,reverse=True) #按字母顺序倒序排序修改
print(cities)3-9晚餐嘉宾names = ['JairZhu','HHL','WilliamZheng']
for name in names:
print (name + " ,would you like to have a dinner with me?")
print("Oops! HHL is busy debuging his program so he cannot attend.")
names[1]="Xuanxuan" #修改名单
for name in names:
print (name + " ,would you like to have a dinner with me?")
print(len(names))3-10尝试使用各个函数cities=['Paris','Chengdu','Mosco','London','Beijing']
cities.append('Shanghai') #尾部添加
print(cities)
cities.insert(0,'Guangzhou') #中间插入
print(cities)
del cities[3] #删除
print(cities)
cities.pop(-1) #特定位置删除
print(cities)
cities.remove('Beijing') #根据值删除
print(cities)
cities.sort() #排序
print(cities)
cities.reverse() #倒序排列
print(cities)
print(len(cities)) #输出列表长度
3-11有意引发错误,使操作一个越界的值即可。
有意触发:names=[]
print(names[-1])
修改:names=['Haha']
print(names[-1])
相关文章推荐
- C++primer[习题][第三章][11-20]
- C++Primer第五版 第三章习题答案(11~20)
- 【TIJ4】第三章全部习题
- 数据结构与算法分析课后习题第三章(11)
- [APUE] 第三章部分习题
- 第三章习题T3
- C++Primer第五版 第十五章习题答案(11~20)
- C++primer[习题][第三章][1-10]
- 《C Primer Plus 》第六版 习题 第三章
- C++Primer第五版 第十八章习题答案(11~20)
- 【第三周】第三章习题3.7
- 《操作系统精髓与设计原理》习题第三章
- coursera 吴恩达 -- 第一课 神经网络和深度学习 :第二周课后习题 Logistic Regression with a Neural Network mindset
- 《C++ Primer》第五版课后习题解答_第三章(2)(06-20)
- 算法入门经典第三章习题(2)
- 刷紫书第三章习题(习题3-1到习题3-6)
- 算法导论课后习题解析 第三章
- c++ primer plus第三章习题答案
- 课后习题2-11
- Coursera Machine Learning 第二周 quiz Octave/Matlab Tutorial 习题答案