3-7 缩减名单

你刚得知新购买的餐桌无法及时送达,因此只能邀请两位嘉宾。
□以完成练习3-6时编写的程序为基础,在程序末尾添加一行代码,打印一条你只能邀请两位嘉宾共进晚餐的消息。
□使用pop()不断地删除名单中的嘉宾,直到只有两位嘉宾为止。每次从名单中弹出一位嘉宾时,都打印一条消息,让该嘉宾知悉你很抱歉,无法邀请他来共进晚餐。
□对于余下的两位嘉宾中的每一位,都打印一条消息,指出他依然在受邀人之列。
□使用del将最后两位嘉宾从名单中删除,让名单变成空的,打印该名单,核实程序结束时名单确实是空的。

代码:

names=["Iron Man","Spider Man","Captain","Ant-Man"]
print(names[0]+","+"do you have time for dinner with me this weenkend?")
print(names[1]+","+"do you have time for dinner with me this weenkend?")
print(names[2]+","+"do you have time for with me this weenkend?")
print(names[3]+","+"do you have time for dinner with me this weenkend?")
print(names[3]+" can't be invited to dinner for some unexpected business.")
print("\nI just found a bigger table for gathering together to have dinner this weekend.")
names.insert(0,'Black Widow')
names.insert(2,'Thor')
names.append('Hulk')
print(names)
print("\nDo you have time for dinner with me this weenkend"+","+names[0]+"?")
print("\nDo you have time for dinner with me this weenkend"+","+names[1]+"?")
print("\nDo you have time for dinner with me this weenkend"+","+names[2]+"?")
print("\nDo you have time for dinner with me this weenkend"+","+names[3]+"?")
print("\nDo you have time for dinner with me this weenkend"+","+names[4]+"?")
print("\nDo you have time for dinner with me this weenkend"+","+names[5]+"?")
print("\nDo you have time for dinner with me this weenkend"+","+names[6]+"?")
print("\nThis weekend I can only invite two people to dinner.")
apology=names.pop()
print("\nI'm really so sorry,"+apology+"."+"Because I don't find a big table, I cannot invite you to dinner this weekend.We can postpone the gathering until the end of the month if you have time.")
print(names)
apology=names.pop()
print("\nI'm really so sorry,"+apology+"."+"Because I don't find a big table, I cannot invite you to dinner this weekend.We can postpone the gathering until the end of the month if you have time.")
print(names)
apology=names.pop()
print("\nI'm really so sorry,"+apology+"."+"Because I don't find a big table, I cannot invite you to dinner this weekend.We can postpone the gathering until the end of the month if you have time.")
print(names)
apology=names.pop()
print("\nI'm really so sorry,"+apology+"."+"Because I don't find a big table, I cannot invite you to dinner this weekend.We can postpone the gathering until the end of the month if you have time.")
print(names)
apology=names.pop()
print("\nI'm really so sorry,"+apology+"."+"Because I don't find a big table, I cannot invite you to dinner this weekend.We can postpone the gathering until the end of the month if you have time.")
print(names)
print("\nSince I couldn't find a big table, the number of people  was reduced to two. "+names [0]+","+"you are still among the invitees. Looking forward to having dinner with you on the weekend.")
print("\nSince I couldn't find a big table, the number of people  was reduced to two. "+names [1]+","+"you are still among the invitees. Looking forward to having dinner with you on the weekend.")
del names[0]
print(names)
del names[0]
print(names)

运行结果:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值