# Arup Guha
# Edited original Kwiki Mart on 7/23/2013
# Kwiki Mart

def main():

    # Store prices and quantities in separate dictionaries.
    myPrices = {}
    myQuantities = {}

    # Populate store.
    createStore(myPrices, myQuantities)

    # Execute user's choices.
    choice = getMenuChoice()
    while choice != "0":
        if choice == "1":
            listItems(myPrices, myQuantities)
        elif choice == "2":
            restock(myQuantities)
        elif choice == "3":
            sellItem(myPrices, myQuantities)
        else:
            print("You made an invalid choice, try again.")

        choice = getMenuChoice()

# Returns the user's menu choice with no error checking.
def getMenuChoice():
    print("""
          Welcome to Kwiki Mart!
          What would you like to do?

          0 -- Quit
          1 -- List Remaining items
          2 -- Restock the store
          3 -- Sell an item
          """)
    
    choice = input(">>>")

    return choice

# Restocks the store.
def restock(quantities):

    # Get item.
    item = input("Whatcha got brotha?")
    count = int(input("How many "+item+" are you adding?\n"))

    # Restock only if it's valid item.
    if item in quantities.keys():
        quantities[item] = quantities[item] + count

    # This implementation doesn't allow new items.
    else:
        print("Sorry, we don't have that item and can't add it.")

# Sell an item.
def sellItem(prices, quantities):

    item=input("Wat u buyin'?")

    # See if we have it...
    if item in prices.keys() and quantities[item] > 0:
    
        money=float(input("How much u payin?"))
        change=money-prices[item]

        # See if you paid enough.
        if change >= 0:
            quantities[item] = quantities[item] - 1
            print("Yo change be $",change, sep="")
        else:
            print("Sorry, that's not enough. You get nothing!!!")

    # Error message for out of stock.
    else:
        print("Sorry, we are currently out of", item)

# Create the store by populating both dictionaries.
def createStore(prices,quantities):

    nstock=int(input("How many new items do you want to add?"))

    # Stock each item individually.
    for i in range(nstock):
        nstock2=input("What do you want to add?")
        price=float(input("How much is it?"))
        quantity = int(input("How many of this item do you have?"))
        prices[nstock2] = price
        quantities[nstock2] = quantity 

# Prints out all information.
def listItems(prices, quantities):

	Keys = prices.keys()
	for Key in Keys:
		print(Key, " ", "$", prices[Key], ",", quantities[Key], sep="")
    
main()
