"""
Sawyer Hood
Grocery list program using functions.

"""
groceries = {}

#Main loop. Initializes the list and asks the user for commands until he/she types 'stop'.
def main():
    
    more_input = True
    while more_input:
        arg = input("Please enter your command 'add/remove/total/stop item number cost':  ")
        
        #Splits the input into separate strings in a list
        arg = arg.split()
        
        #The next if statements look for the command and pass the rest of the arguments to the respective functions 
        if arg[0] == "remove":
            remove(arg)
        elif arg[0] == "add":
            add(arg)
        elif arg[0] == "total":
            printTotal()
        elif arg[0] == "print":
            printList()
        elif arg[0] == "stop":
            more_input = False
        else:
            print("Command not recognized.")
            
#removes an item from the grocery list.
def remove(arg):
    if len(arg) < 2:
        print("Please enter a name for the item.")
    else:
        del groceries[arg[1]]
  
#adds an item to the grocery list.      
def add(arg):
    if len(arg) < 4:
        print("The 'add' command should have 4 arguments...")
    else:
        groceries[arg[1]] = [arg[2],arg[3]]

#Returns the total cost of all of the items in the grocery list.   
def total():
    total = 0
    for key in groceries:
        item = groceries[key]
        total += float(item[0]) * int(item[1])
        print(item)
    return total

#Prints all of the items and their price and how many on separate lines.
def printList():
    for key in groceries:
        item = groceries[key]
        print("{0}: ${1}, {2}".format(key, item[0], item[1]))
        
#Prints the total cost of the items.     
def printTotal():
    print("Your total is: $" + str(total()))

#Returns the name of the most expensive item.
def most_expensive():
    max_cost = 0
    for key in groceries:
        item = groceries[key]
        cost = item[0] * item[1]
        if cost > max:
            max_cost = cost
    return max_cost
        

    
main()