Vending machine is a machine which dispenses goods/items such as snacks, soft
drinks, chocolates, cookies, chips and other selected items to customers automatically,
after the customer inserts currency or coins into the machine.

The project is required to design, implement to simulate a vending machine. The program will work with item names, their prices, and the current number available in the machine. The machine should display different items. When the application starts, the vending machine will display each type of goods or items and number of items available in the machine. Each time the customer selects an item, the application should subtract 1 from the quantity of the selected item. It should also update and display the total amount of sales. The customer should be able to buy multiple items during the same session.

The customer can either quit the program or pick an item from the machine. If the user
selects an item, the program will notify the customer that an amount must be entered for
payment. The program will then display the amount of change that would be returned
and subtract one from the number of items left in the machine for that item. If the customer selects an item that is sold out, a message to that effect will be displayed. The loop then repeats. When the customer chooses to quit the program, the program must display the total amount of sales the machine earned during the current run. Then, print out a summary table of the machine's final state, which includes the drink names, prices,
and food items available in the machine at that point.

The program should do the following:

  1. Show the customer the different products sold by the candy machine as Main Menu
  2. The available quantity as well as the cost of each item
  3. Let the customer make the selection.
  4. Show the customer the cost of the item selected.
  5. Accept money from the customer.
  6. Release the item.
  7. Display a summary report which includes the total sales of all items (itemized) at the end of the day
  8. Show all error messages with correction actions
  9. Perform input data validation to ensure correct input has been entered
  10. Exit the application

Dani AI

Generated

A compact implementation plan, common pitfalls, and a minimal Python skeleton to close the gap between the assignment by and the "show your work" advice from . Focus on a clear data model, robust input validation, and integer-based money handling so the program behaves predictably across sessions.

Use a small in-memory model: one list of item dicts (id, name, price_cents, qty, sold). Keep all money in cents to avoid float rounding. A very small skeleton to illustrate the flow:

items = [
    {'id': 1, 'name': 'Soda',  'price_cents': 150, 'qty': 10, 'sold': 0},
    {'id': 2, 'name': 'Chips', 'price_cents': 125, 'qty': 5,  'sold': 0},
]

def cents_to_str(c): return f"${c/100:.2f}"

def purchase(item):
    if item['qty'] <= 0:
        raise RuntimeError('sold out')
    paid = 0
    while paid < item['price_cents']:
        try:
            coin = int(input("Insert cents (e.g. 25): "))
            if coin <= 0: raise ValueError
        except ValueError:
            print("Invalid amount; insert whole cents.")
            continue
        paid += coin
    item['qty'] -= 1
    item['sold'] += 1
    return paid - item['price_cents']  # change in cents

Validation and UX notes: always catch non-integer input, reject negative or zero coin entries, allow cancellation mid-payment (return inserted amount), and handle sold-out selections with a clear message. Track itemized sales by summing sold * price_cents per item for the end-of-session report. Test these cases explicitly: exact change, overpay, partial payments then cancel, and buying until sold out.

For a stronger solution add small unit tests around the purchase flow and consider optional persistence (JSON/CSV) if session state should survive restarts. As suggested, pasting a current code attempt will let responders give focused fixes.

Please take time when you create a new discussion. This reads as if you dumped some homework assignment here. That rarely ends well.

Show your work, explain where you had an issue you couldn't overcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.