这是我的代码,按道理来说应当在最后列表guest中只剩下2个元素才对,但我发现列表最后始终剩有4个元素,是哪里有问题吗?
guest=["Jhoney","Peter","May","Harry","Linus"]
length=len(guest)
for i in guest:
print("It's my presure to have you here,"+i+".")
print("But it's a pity that Harry can't come with us.")
guest[3]="Gredy"
for i in guest:
print("It's my presure to have you here,"+i+".")
print("HEY,that's good,we have a bigger table now.")
guest.insert(0,"Miky")
guest.insert(3,"Minny")
guest.append("Macduck")
print(guest)
for i in guest:
print("It's my presure to have you here,"+i+".")
print("Sorry to announce that I could only invite two of you now.")
for a in guest:
if length>5:
a=guest.pop()
length=len(guest)
print("I'm so sorry that I can't have you with me now,"+a+".")
print(guest)
guest=["Jhoney","Peter","May","Harry","Linus"]
length=len(guest)
for i in guest:
print("It's my presure to have you here,"+i+".")
print("But it's a pity that Harry can't come with us.")
guest[3]="Gredy"
for i in guest:
print("It's my presure to have you here,"+i+".")
print("HEY,that's good,we have a bigger table now.")
guest.insert(0,"Miky")
guest.insert(3,"Minny")
guest.append("Macduck")
print(guest)
for i in guest:
print("It's my presure to have you here,"+i+".")
print("Sorry to announce that I could only invite two of you now.")
for a in guest:
if length>5:
a=guest.pop()
length=len(guest)
print("I'm so sorry that I can't have you with me now,"+a+".")
print(guest)