# Arup Guha
# 11/12/2020
# Grocery Store Example

ADD = 1
BUY = 2
SEE = 3
QUIT = 4

def menu():
    print("Which option would you like?")
    print("1. Add stock of an item.")
    print("2. Buy an item.")
    print("3. See the whole stock.")
    print("4. Quit.")
    return int(input(""))

def main():

    # My grocery store.
    store = {}

    # Get the user's choice.
    choice = menu()

    # Keep going till we quit.
    while choice != QUIT:

        # Adding an item.
        if choice == ADD:

            # Get item and how much.
            item = input("Which item are you stocking?\n")
            quantity = int(input("How many of them are you adding?\n"))

            # Already in stock, so adjust.
            if item in store:
                store[item] += quantity

            # New, so add it!
            else:
                store[item] = quantity

        # Buying an item.
        elif choice == BUY:

            # Get item and how much.
            item = input("Which item do you want to buy?\n")
            quantity = int(input("How many of them do you want to buy?\n"))

            if not item in store:
                print("Sorry, we don't have that item.")

            # Whole stock will be removed.
            elif quantity >= store[item]:

                print("You have wiped us out, you receive",store[item],"number of",item)
                del store[item]

            # We have enough and leftover so sell and update stock.
            else:
                print("Great, we have enough to sell you!")
                store[item] -= quantity

        # Mostly to see if this is working or not.
        elif choice == SEE:
            print("Here is our inventory:")
            print(store)

        # Error msg.
        elif choice != QUIT:
            print("Sorry that was an invalid choice. Try again.")

        # Get next choice.
        choice = menu()

    # Ending message.
    print("Thanks for shopping with us.")

main()


            
