欢迎来到冰豆网! | 帮助中心 分享价值,成长自我!
冰豆网
全部分类
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • 党团工作>
  • ImageVerifierCode 换一换
    首页 冰豆网 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    SolutionsChapter 3.docx

    • 资源ID:28153895       资源大小:16.50KB        全文页数:11页
    • 资源格式: DOCX        下载积分:10金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    SolutionsChapter 3.docx

    1、Solutions Chapter 3Solutions - Chapter 33-1: NamesStore the names of a few of your friends in a list callednames. Print each persons name by accessing each element in the list, one at a time.names = ron, tyler, daniprint(names0)print(names1)print(names2)Output:rontylerdani3-2: GreetingsStart with th

    2、e list you used in Exercise 3-1, but instead of just printing each persons name, print a message to them. The text of each message should be the same, but each message should be personalized with the persons name.names = ron, tyler, danimsg = Hello, + names0.title() + !print(msg)msg = Hello, + names

    3、1.title() + !print(msg)msg = Hello, + names2.title() + !print(msg)Output:Hello, Ron!Hello, Tyler!Hello, Dani!3-4: Guest ListIf you could invite anyone, living or deceased, to dinner, who would you invite? Make a list that includes at least three people youd like to invite to dinner. Then use your li

    4、st to print a message to each person, inviting them to dinner.guests = guido van rossum, jack turner, lynn hillname = guests0.title()print(name + , please come to dinner.)name = guests1.title()print(name + , please come to dinner.)name = guests2.title()print(name + , please come to dinner.)Output:Gu

    5、ido Van Rossum, please come to dinner.Jack Turner, please come to dinner.Lynn Hill, please come to dinner.3-5: Changing Guest ListYou just heard that one of your guests cant make the dinner, so you need to send out a new set of invitations. Youll have to think of someone else to invite. Start with y

    6、our program from Exercise 3-4. Add aprintstatement at the end of your program stating the name of the guest who cant make it. Modify your list, replacing the name of the guest who cant make it with the name of the new person you are inviting. Print a second set of invitation messages, one for each p

    7、erson who is still in your list.# Invite some people to dinner.guests = guido van rossum, jack turner, lynn hillname = guests0.title()print(name + , please come to dinner.)name = guests1.title()print(name + , please come to dinner.)name = guests2.title()print(name + , please come to dinner.)name = g

    8、uests1.title()print(nSorry, + name + cant make it to dinner.)# Jack cant make it! Lets invite Gary instead.del(guests1)guests.insert(1, gary snyder)# Print the invitations again.name = guests0.title()print(n + name + , please come to dinner.)name = guests1.title()print(name + , please come to dinner

    9、.)name = guests2.title()print(name + , please come to dinner.)Output:Guido Van Rossum, please come to dinner.Jack Turner, please come to dinner.Lynn Hill, please come to dinner.Sorry, Jack Turner cant make it to dinner.Guido Van Rossum, please come to dinner.Gary Snyder, please come to dinner.Lynn H

    10、ill, please come to dinner.3-6: More GuestsYou just found a bigger dinner table, so now more space is available. Think of three more guests to invite to dinner. Start with your program from Exercise 3-4 or Exercise 3-5. Add aprintstatement to the end of your program informing people that you found a

    11、 bigger dinner table. Useinsert()to add one new guest to the beginning of your list. Useinsert()to add one new guest to the middle of your list. Useappend()to add one new guest to the end of your list. Print a new set of invitation messages, one for each person in your list.# Invite some people to d

    12、inner.guests = guido van rossum, jack turner, lynn hillname = guests0.title()print(name + , please come to dinner.)name = guests1.title()print(name + , please come to dinner.)name = guests2.title()print(name + , please come to dinner.)name = guests1.title()print(nSorry, + name + cant make it to dinn

    13、er.)# Jack cant make it! Lets invite Gary instead.del(guests1)guests.insert(1, gary snyder)# Print the invitations again.name = guests0.title()print(n + name + , please come to dinner.)name = guests1.title()print(name + , please come to dinner.)name = guests2.title()print(name + , please come to din

    14、ner.)# We got a bigger table, so lets add some more people to the list.print(nWe got a bigger table!)guests.insert(0, frida kahlo)guests.insert(2, reinhold messner)guests.append(elizabeth peratrovich)name = guests0.title()print(name + , please come to dinner.)name = guests1.title()print(name + , ple

    15、ase come to dinner.)name = guests2.title()print(name + , please come to dinner.)name = guests3.title()print(name + , please come to dinner.)name = guests4.title()print(name + , please come to dinner.)name = guests5.title()print(name + , please come to dinner.)Output:Guido Van Rossum, please come to

    16、dinner.Jack Turner, please come to dinner.Lynn Hill, please come to dinner.Sorry, Jack Turner cant make it to dinner.Guido Van Rossum, please come to dinner.Gary Snyder, please come to dinner.Lynn Hill, please come to dinner.We got a bigger table!Frida Kahlo, please come to dinner.Guido Van Rossum,

    17、please come to dinner.Reinhold Messner, please come to dinner.Gary Snyder, please come to dinner.Lynn Hill, please come to dinner.Elizabeth Peratrovich, please come to dinner.3-7: Shrinking Guest ListYou just found out that your new dinner table wont arrive in time for the dinner, and you have space

    18、 for only two guests. Start with your program from Exercise 3-6. Add a new line that prints a message saying that you can invite only two people for dinner. Usepop()to remove guests from your list one at a time until only two names remain in your list. Each time you pop a name from your list, print

    19、a message to that person letting them know youre sorry you cant invite them to dinner. Print a message to each of the two people still on your list, letting them know theyre still invited. Usedelto remove the last two names from your list, so you have an empty list. Print your list to make sure you

    20、actually have an empty list at the end of your program.# Invite some people to dinner.guests = guido van rossum, jack turner, lynn hillname = guests0.title()print(name + , please come to dinner.)name = guests1.title()print(name + , please come to dinner.)name = guests2.title()print(name + , please c

    21、ome to dinner.)name = guests1.title()print(nSorry, + name + cant make it to dinner.)# Jack cant make it! Lets invite Gary instead.del(guests1)guests.insert(1, gary snyder)# Print the invitations again.name = guests0.title()print(n + name + , please come to dinner.)name = guests1.title()print(name +

    22、, please come to dinner.)name = guests2.title()print(name + , please come to dinner.)# We got a bigger table, so lets add some more people to the list.print(nWe got a bigger table!)guests.insert(0, frida kahlo)guests.insert(2, reinhold messner)guests.append(elizabeth peratrovich)name = guests0.title

    23、()print(name + , please come to dinner.)name = guests1.title()print(name + , please come to dinner.)name = guests2.title()print(name + , please come to dinner.)name = guests3.title()print(name + , please come to dinner.)name = guests4.title()print(name + , please come to dinner.)name = guests5.title

    24、()print(name + , please come to dinner.)# Oh no, the table wont arrive on time!print(nSorry, we can only invite two people to dinner.)name = guests.pop()print(Sorry, + name.title() + theres no room at the table.)name = guests.pop()print(Sorry, + name.title() + theres no room at the table.)name = gue

    25、sts.pop()print(Sorry, + name.title() + theres no room at the table.)name = guests.pop()print(Sorry, + name.title() + theres no room at the table.)# There should be two people left. Lets invite them.name = guests0.title()print(name + , please come to dinner.)name = guests1.title()print(name + , pleas

    26、e come to dinner.)# Empty out the list.del(guests0)del(guests0)# Prove the list is empty.print(guests)Output:Guido Van Rossum, please come to dinner.Jack Turner, please come to dinner.Lynn Hill, please come to dinner.Sorry, Jack Turner cant make it to dinner.Guido Van Rossum, please come to dinner.G

    27、ary Snyder, please come to dinner.Lynn Hill, please come to dinner.We got a bigger table!Frida Kahlo, please come to dinner.Guido Van Rossum, please come to dinner.Reinhold Messner, please come to dinner.Gary Snyder, please come to dinner.Lynn Hill, please come to dinner.Elizabeth Peratrovich, pleas

    28、e come to dinner.Sorry, we can only invite two people to dinner.Sorry, Elizabeth Peratrovich theres no room at the table.Sorry, Lynn Hill theres no room at the table.Sorry, Gary Snyder theres no room at the table.Sorry, Reinhold Messner theres no room at the table.Frida Kahlo, please come to dinner.

    29、Guido Van Rossum, please come to dinner.3-8: Seeing the WorldThink of at least five places in the world youd like to visit. Store the locations in a list. Make sure the list is not in alphabetical order. Print your list in its original order. Dont worry about printing the list neatly, just print it

    30、as a raw Python list. Usesorted()to print your list in alphabetical order without modifying the actual list. Show that your list is still in its original order by printing it. Usesorted()to print your list in reverse alphabetical order without changing the order of the original list. Show that your list is still in its original order by printing it again. Usereverse()to change the order of your list. Print the list to show that its order has changed. User


    注意事项

    本文(SolutionsChapter 3.docx)为本站会员主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2022 冰点文档网站版权所有

    经营许可证编号:鄂ICP备2022015515号-1

    收起
    展开