<
Python 练习题
>
上一篇

收藏的趣味项目
下一篇

Vim 编辑器学习

Python 学习总结及题目练习。

列表简介 练习题

嘉宾名单:如果你可以邀请任何人一起共进晚餐(无论是在世的还是故去的),你会邀请哪些人?

修改嘉宾名单:你刚得知有位嘉宾无法赴约,因此需要另外邀请一位嘉宾。

添加嘉宾:你刚找到了一个更大的餐桌,可容纳更多的嘉宾。请想想你还想邀请哪三位嘉宾。

缩减名单:你刚得知新购买的餐桌无法及时送达,因此只能邀请两位嘉宾。

names = ['jack','michael','lucy']
message0 = "Hi " + names[0].title() + ", welcome to my party."
message1 = "Hi " + names[1].title() + ", welcome to my party."
message2 = "Hi " + names[2].title() + ", welcome to my party.\n"
print(message0)
print(message1)
print(message2)

message_absence = names[2].title() + "is ansence."
print(message_absence)
names[2] = 'jallen'
message0 = "Hi " + names[0].title() + ", welcome to my party."
message1 = "Hi " + names[1].title() + ", welcome to my party."
message2 = "Hi " + names[2].title() + ", welcome to my party.\n"
print(message0)
print(message1)
print(message2)

print("I have found a bigger table.")
new1 = names.insert(0,'monkey')
new2 = names.insert(2,'lau')
new3 = names.append('pig')
message0 = "Hi " + names[0].title() + ", welcome to my party."
message1 = "Hi " + names[1].title() + ", welcome to my party."
message2 = "Hi " + names[2].title() + ", welcome to my party."
message3 = "Hi " + names[3].title() + ", welcome to my party."
message4 = "Hi " + names[4].title() + ", welcome to my party."
message5 = "Hi " + names[5].title() + ", welcome to my party.\n"
print(message0)
print(message1)
print(message2)
print(message3)
print(message4)
print(message5)

print("Table is not enough, so i can only welcome two people to come.")
people0 = names.pop(0)
out0 = people0.title() + " is out."
print(out0)
people1 = names.pop(0)
out1 = people1.title() + " is out."
print(out1)
people2 = names.pop(0)
out2 = people2.title() + " is out."
print(out2)
people3 = names.pop(0)
out3 = people3.title() + " is out."
print(out3)
message0 = "Hi " + names[0].title() + ", welcome to my party."
message1 = "Hi " + names[1].title() + ", welcome to my party.\n"
print(message0)
print(message1)

print("Empty list")
del names[0]
del names[0]
print(names)
Top
Foot