Python Programming Quick Start 5th Chapter Practical Project Reference Answer

Source: Internet
Author: User

1#!/usr/bin/env python3.52#Coding:utf-83#5.6.14#List of items for fun games5#given a dictionary that contains the item name and quantity, and prints out the quantity corresponding to the item6 7 Dict_stuff = {'Rope': 1,'Torch': 6,'Gold coin': 42,'Dagger': 1,'Arrow': 12}  8Print("5.6.1 Reference Answers")  9Print('='* 80) 10Print("Given dictionary:", Dict_stuff)11Print("Operation Result:") 12defDisplayinventory (Inventory):13Print("Inventory:") Item_total =015 forKvinchInventory.items ():16Print(Str (v) +'\ t'+k)Item_total + =v18Print("Total number of items:"+str (item_total))19displayinventory (Dict_stuff)20Print('='* 80) 21stPrint() 22#5.6.2Dragonloot = ['Gold coin','Dagger','Gold coin','Gold coin','Ruby'] 24Print("5.6.2 Reference Answers") 25Print('='* 80) INV = {'Gold coin': 42,'Rope': 1} 27Print("given list:", Dragonloot)28Print("Given dictionary:", INV)29Print("Operation Result:") 30defaddtoinventory (inventory,addeditems):31 forIteminchDragonloot:32ifItem not inchInventory.keys ():33Inventory.setdefault (Item,addeditems.count (item))34Else: + Inventory[item] + = 1 36returnInventoryNotoginseng INV =addtoinventory (inv,dragonloot)38Print(INV)39displayinventory (INV)40Print('='* 80)

Python Programming Quick Start 5th Chapter Practical Project Reference Answer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.