python从⼊门到实践答案_python编程:从⼊门到实践习题3-
4~3-7
3-4 嘉宾名单:
如果你可以邀请任何⼈⼀起共进晚餐(⽆论是在世的还是故去的), 你会邀请哪些⼈?请创建⼀个列表,其中包含⾄少 3个你想邀请的⼈;然后,使⽤这个 列表打印消息,邀请这些⼈来与你共进晚餐。
guests_list=['Bill Gates','Mao ze dong','Qin shi huang']
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+" and "+guests_list[2]+" to my party.")
3-5 修改嘉宾名单:
你刚得知有位嘉宾⽆法赴约,因此需要另外邀请⼀位嘉宾。
以完成练习 3-4时编写的程序为基础,在程序末尾添加⼀条 print 语句,指出哪 位嘉宾⽆法赴约。
修改嘉宾名单,将⽆法赴约的嘉宾的姓名替换为新邀请的嘉宾的姓名。js特效代码使用方法
再次打印⼀系列消息,向名单中的每位嘉宾发出邀请。
guests_list=['Bill Gates','Mao ze dong','Qin shi huang']
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+" and "+guests_list[2]+" to my party.")
print("I've been told that "+guests_list[0]+" can't attend to my party")
guests_list[0]='Bill Herrington'
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+" and "+guests_list[2]+" to my party.")
3-6 添加嘉宾:
你刚到了⼀个更⼤的餐桌,可容纳更多的嘉宾。请想想你还想邀 请哪三位嘉宾。
以完成练习 3-4或练习 3-5时编写的程序为基础,在程序末尾添加⼀条 print 语 句,指出你到了⼀个更⼤的餐桌。
使⽤ insert()将⼀位新嘉宾添加到名单开头。
使⽤ insert()将另⼀位新嘉宾添加到名单中间。
使⽤ append()将后⼀位新嘉宾添加到名单末尾。
ahrefs是什么意思啊打印⼀系列消息,向名单中的每位嘉宾发出邀请。
guests_list=['Bill Gates','Mao ze dong','Qin shi huang']
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+" and "+guests_list[2]+" to my party.")
print("I've been told that "+guests_list[0]+" can't attend to my party")
guests_list[0]='Bill Herrington'
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+" and "+guests_list[2]+" to my party.")
print("I found a bigger table that can have more people to my party!")
guests_list.insert(0,'Lan lulu')
tributariesguests_list.insert(2,'Jin kela')
guests_list.append('Cai xu kun')
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+","+guests_list[2]+","+guests_list[3]+","+guests_list[4]+" and
"+guests_list[5]+" to my party.")
3-7 缩减名单:
你刚得知新购买的餐桌⽆法及时送达,因此只能邀请两位嘉宾。
以完成练习 3-6时编写的程序为基础,在程序末尾添加⼀⾏代码,打印⼀条你只 能邀请两位嘉宾共进晚餐的消息。
使⽤ pop()不断地删除名单中的嘉宾,直到只有两位嘉宾为⽌。每次从名单中弹 出⼀位嘉宾时,都打印⼀条消息,让该嘉宾知悉你很抱歉,⽆法邀请他来共进 晚餐。
对于余下的两位嘉宾中的每⼀位,都打印⼀条消息,指出他依然在受邀⼈之列。
使⽤ del 将后两位嘉宾从名单中删除,让名单变成空的。打印该名单,核实程 序结束时名单确实是空的。
guests_list=['Bill Gates','Mao ze dong','Qin shi huang']
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+" and "+guests_list[2]+" to my party.")
print("I've been told that "+guests_list[0]+" can't attend to my party")
guests_list[0]='Bill Herrington'
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+" and "+guests_list[2]+" to my party.")
print("I found a bigger table that can have more people to my party!")
guests_list.insert(0,'Lan lulu')
guests_list.insert(2,'Jin kela')
guests_list.append('Cai xu kun')
print("I'd like to invite "+guests_list[0]+","+guests_list[1]+","+guests_list[2]+","+guests_list[3]+","+guests_list[4]+" and
"+guests_list[5]+" to my party.")
print("The new table couldn't arrive in time,so only two of you can be invited.")
表单制作注意事项
abandonded_guest=guests_list.pop(0)
学python编程入门print("Sorry about that,"+abandonded_guest+".")
abandonded_guest=guests_list.pop(0)
print("Sorry about that,"+abandonded_guest+".")
abandonded_guest=guests_list.pop(0)
print("Sorry about that,"+abandonded_guest+".")
abandonded_guest=guests_list.pop(0)
print("Sorry about that,"+abandonded_guest+".")
print("Come and have fun with us,"+guests_list[0]+".")
print("Come and have fun with us,"+guests_list[1]+".")
del guests_list[0]
del guests_list[0]
print(guests_list)
java羊了个羊源码

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。