3-1:
names=["张三","李四","王五"]
print(names[0])
print(names[1])
print(names[2])
3-2:
names=["张三","李四","王五"]
for a in names:
print(a+" 早上好!")
3-3:
ways=["walk","bus","boat"]
for item in ways:
print("I would like to go to school by "+item)
3-4:
names=["张三","李四","王五"]
for person in names:
print( person+", would you like to come to\
my home and have a dinner with me?")
print(names[0]+"can't attend this dinner")
3-5:
print(names[0]+" can't attend this dinner")
names[0]="小明"
for person in names:
print( person+", would you like to come to\
my home and have a dinner with me?")
3-6:
print("I find a big table ,so I want to invite more friends")
names.insert(0,"小华")
names.insert(2,"小张")
names.append("小刘")
for person in names:
print( person+", would you like to come to\
my home and have a dinner with me?")
3-7:
print("I can only invite two people to my home because\
the big table cant send my house in time")
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
for person in names:
print(person+" you can come to my house and have a dinner with me ")
del names[1]
del names[0]
print(names)
3-8:
cities=["ShangHai","Beijing","ChengDu","TianJin","HuNan"]
print(cities)
print(sorted(cities))
print(cities)
#sorted(reverse=True)没成功
cities.reverse()
print(cities)
cities.reverse()
print(cities)
cities.sort()
print(cities)
cities.sort(reverse=True)
print(cities)