# 练习 3.1
names = ['pig', 'dog', 'cat', 'tiger']
print(names[0])
print(names[1])
print(names[2])
print(names[-1])
for name in names:
print(name)
# 练习3.2
for name in names:
print(name+':\ti am so happy')
# 练习3.3
trans = ['by', 'car', 'subway', 'bus']
print(trans[2]+'\tis so convenient')
# 练习3.4
names2 = ['s', 'm', 'l', 'xl', 'xxl']
for name in names2:
print(f"Dear{name} \n I want to invite you to participate my wedding")
# 练习3.5 修改嘉宾名单
print(names2[-1])
name3 = names2.pop()
print(name3)
names2.insert(4, 'xxxl')
print(names2)
# 练习3.6 添加嘉宾
print('I find a larger table.')
names2.insert(0,'ss')
names2.insert(3,'lx')
names2.append(' xxxxl ')
print(names2)
for name in names2:
print(f"Dear {name} \n I want to invite you to participate my wedding")
# 练习3.7 缩短名单
print('i am sorry about that i could invite only two guests')
while(len(names2)>2):
name4=names2.pop()
print(f"Dear {name4} i am sorry about that i could invite only two guests")