python课程作业——第3章 列表简介

第3章 列表简介

这里写图片描述

# 3-4
inviter = ["Alice", "Bob", "Cindy"]

for member in inviter:
    print("Welcome " + member + ", you are invited to the dinner")


# 3-5
inviter = ["Alice", "Bob", "Cindy"]

print("Alice cannot come to the party")
inviter.remove("Alice")

for member in inviter:
    print("Welcome " + member + ", you are invited to the party")


# 3-6
inviter = ["Alice", "Bob", "Cindy"]

inviter.insert(0, "Ace")
inviter.insert((len(inviter)+1)//2, "Mark")
inviter.append("Zero")

for member in inviter:
    print("Welcome " + member + ", you are invited to the party")


# 3-7
inviter = ["Alice", "Bob", "Cindy"]

inviter.insert(0, "Ace")
inviter.insert((len(inviter)+1)//2, "Mark")
inviter.append("Zero")

while len(inviter) > 2:
    member = inviter.pop()
    print("Sorry " + member + ", we will not invite you to the party")

print()

print("The size of the inviter list is: " + str(len(inviter)))
for member in inviter:
    print("Welcome " + member + ", you are invited to the party")

print()

del inviter[0]
del inviter[0]
print("The size of the inviter list is: " + str(len(inviter)))
print(inviter)

猜你喜欢

转载自blog.csdn.net/yeziqing10/article/details/80628720