# Helene Martin, Garfield High School # Inventory program demonstrates advanced use of lists from random import * # for using the shuffle function # print_inv takes a list as a parameter and prints out info about it def print_inv(inventory): # the len function tells us how many items are in a list print("You have " + str(len(inventory)) + " items:") for item in inventory: print item print inventory = ["sword", "ruby", "staff", "potion", "armor"] # calling the function I wrote at top print_inv(inventory) # accessing a specific item index = int(raw_input("Enter an index number for an inventory item: ")) print("That is a " + inventory[index]) # checking to see if an item is in the list item = raw_input("Tell me an item to search for: ") if(item in inventory): print("You do have that.") else: print("Sorry, you don't have that yet.") # adding two lists chest = ["pearls", "coins"] print("You find a treasure chest that contains " + str(len(chest)) + " items!") inventory = inventory + chest print_inv(inventory) print("You trade your coins for a crossbow") inventory[-1] = "crossbow" # access the last element in the list this way print_inv(inventory) print("Your backpack gets all tossed around") shuffle(inventory) # randomly re-orders the list print_inv(inventory) print("You randomly grab something from your backpack") index = randint(0, len(inventory)) print(inventory[index])