Skip to main content

Project: Treasure Hunter

For this section's project, we're going to creating a means of storing inventory information for a character in a treasure hunting game. We're also going to create functions to add items to the inventory, print out details about the inventory, and update the values associated with existing items.

Here's what the application should do:

  1. Define an initial state for the character's inventory. These can be any items you like, such as rope, coins, gems, etc.
    • The inventory should be created using a dictionary, with the items as keys.
    • The values associated with each key should be numbers representing how many of that item the character has. For example, 1 rope and 10 coins.
  2. Define a function for adding an item to the dictionary.
    • It should take in two arguments, one representing the item name, and the other representing the quantity.
    • Items with the same name but different cases should be considered the same item. For example, Rope and rope are the same.
    • As a bonus, you can define some default arguments for if this function is called without an item or key. The defaults can be whatever you like, for example 10 coins.
  3. Define a function for printing the value of a specific item in the inventory.
    • If the item does not exist in the inventory dictionary, inform the user that the treasure hunter doesn't have any of what they searched for.
  4. Define a function for printing out the entire inventory list.
    • You can format the output any way you like, but you should list a name and quantity for each item.
    • Hint: You may want to look back at the section on loops for this function.

If you want an extra challenge, define a function for removing items from the dictionary, or for adding several items at once.

Here's an editor for you to try it out. Alternatively, create your own repl by going to https://repl.it/languages