# Dict Mini Project — Shopping List
# items with quantity and price, total at checkout
# redhorndev.com

# ─────────────────────────────────────────────
# Setup
# ─────────────────────────────────────────────

shopping = {}

# ─────────────────────────────────────────────
# Helper — print current list
# ─────────────────────────────────────────────

def print_list(d):
    if not d:
        print("Your list is empty.")
    else:
        print("\nYour list:")
        for item, data in d.items():
            subtotal = data["qty"] * data["price"]
            print(f"- {item:<10} x{data['qty']}   ${subtotal:.2f}")

# ─────────────────────────────────────────────
# Main loop
# ─────────────────────────────────────────────

while True:
    print("\n1 — Add item")
    print("2 — Remove item")
    print("3 — View list")
    print("4 — Checkout")
    print("5 — Quit")
    choice = input("Your choice: ")

    if choice == "1":
        name  = input("Item name: ").capitalize()
        qty   = int(input("Quantity: "))
        price = float(input("Price per unit: $"))
        shopping[name] = {"qty": qty, "price": price}
        print("Added.")

    elif choice == "2":
        name = input("Item to remove: ").capitalize()
        if name in shopping:
            shopping.pop(name)
            print(f"{name} removed.")
        else:
            print(f'"{name}" is not on your list.')

    elif choice == "3":
        print_list(shopping)

    elif choice == "4":
        if not shopping:
            print("Your list is empty.")
        else:
            print("\n--- Checkout ---")
            total = 0
            for item, data in shopping.items():
                subtotal = data["qty"] * data["price"]
                total += subtotal
                print(f"{item:<10} x{data['qty']}   ${subtotal:.2f}")
            print(f"Total:         ${total:.2f}")

    elif choice == "5":
        print("Out.")
        break

    else:
        print("Invalid choice. Enter 1 to 5.")
