Practice Projects For practice, write programs to do the following tasks. Fantasy Game Inventory You are creating a fantasy video game. The data structure to model the player's inventory will be a dictionary where the keys are string values describing the item in the inventory and the value is an integer value detail- ing how many of that item the player has. For example, the dictionary value ('rope': 1, torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12) means the player has 1 rope, 6 torches, 42 gold coins, and so on. Write a function named displayInventory() that would take any possible "inventory" and display it like the following: Inventory: 12 arrow 42 gold coin 1 горе 6 torch 1 dagger Total number of items: 62 Hint: You can use a for loop to loop through all the keys in a dictionary. # inventory.py stuff - ('rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12) def displayInventory(inventory): print("Inventory:") item total - 0 for k, v in inventory.items (): print(str(v) + + k) item total + v print("Total number of items: "+ str(item_total)) displayInventory(stuff)
Practice Projects For practice, write programs to do the following tasks. Fantasy Game Inventory You are creating a fantasy video game. The data structure to model the player's inventory will be a dictionary where the keys are string values describing the item in the inventory and the value is an integer value detail- ing how many of that item the player has. For example, the dictionary value ('rope': 1, torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12) means the player has 1 rope, 6 torches, 42 gold coins, and so on. Write a function named displayInventory() that would take any possible "inventory" and display it like the following: Inventory: 12 arrow 42 gold coin 1 горе 6 torch 1 dagger Total number of items: 62 Hint: You can use a for loop to loop through all the keys in a dictionary. # inventory.py stuff - ('rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12) def displayInventory(inventory): print("Inventory:") item total - 0 for k, v in inventory.items (): print(str(v) + + k) item total + v print("Total number of items: "+ str(item_total)) displayInventory(stuff)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question

Transcribed Image Text:Practice Projects
For practice, write programs to do the following tasks.
Fantasy Game Inventory
You are creating a fantasy video game. The data structure to model the
player's inventory will be a dictionary where the keys are string values
describing the item in the inventory and the value is an integer value detail-
ing how many of that item the player has. For example, the dictionary value
{'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12} means the
player has 1 rope, 6 torches, 42 gold coins, and so on.
Write a function named displayInventory
"inventory" and display it like the following:
that would take any possible
Inventory:
12 arrow
42 gold coin
1 rope
6 torch
1 dagger
Total number of items: 62
Hint: You can use a for loop to loop through all the keys in a dictionary.
# inventory.py
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12)
def displayInventory(inventory):
print("Inventory:")
item_total - 0
for k, v in inventory.items ():
print(str(v) + ' + k)
item_total += v
print("Total number of items:
+ str(item_total))
displayInventory(stuff)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY