3-4 嘉宾名单:如果你可以邀请任何人一起共进晚餐(无论是在世的还是故去的),
你会邀请哪些人?请创建一个列表,其中包含至少 3 个你想邀请的人;然后,使用这个列表打印消息,邀请这些人来与你共进晚餐。person_invited =['jim','jack','lucy']print(person_invited[0].title()+",i would like to invite you for dinner!")print(person_invited[1].title()+",i would like to invite you for dinner!")print(person_invited[2].title()+",i would like to invite you for dinner!")
F5运行:
Jim,i would like to invite you for dinner!
Jack,i would like to invite you for dinner!
Lucy,i would like to invite you for dinner!
3-5 修改嘉宾名单:你刚得知有位嘉宾无法赴约,因此需要另外邀请一位嘉宾。
以完成练习 3-4 时编写的程序为基础,在程序末尾添加一条 print 语句,指出哪位嘉宾无法赴约。 修改嘉宾名单,将无法赴约的嘉宾的姓名替换为新邀请的嘉宾的姓名。 再次打印一系列消息,向名单中的每位嘉宾发出邀请。person_invited =['jim','jack','lucy']print("\tMr.jim unable to attend!,I will invite kate !")person_invited[0] = 'kate'print(person_invited)print(person_invited[0]+",i would like to invite you for dinner!")print(person_invited[1]+",i would like to invite you for dinner!")print(person_invited[2]+",i would like to invite you for dinner!")
Mr.jim unable to attend!,I will invite kate ! ['kate','jack','lucy']
kate,i would like to invite you for dinner!
jack,i would like to invite you for dinner!
Lucy,i would like to invite you for dinner!