Mechatronics
Documentation for ME 405 labs
Lab0x01

Files

file  Vendotron.py
 Runs a vending machine emulator in the terminal.
 

Classes

class  Vendotron.Drink
 A small struct representing a drink. More...
 
class  Vendotron.Currency
 A small struct representing a denomination of US currency. More...
 
class  Vendotron.State
 The current state of the Vendotron. More...
 

Functions

def Vendotron.display (message)
 Display a Vendotron message in a pretty format. More...
 
def Vendotron.get_change (price, payment)
 Calculate the change required based on a given payment. More...
 
def Vendotron.handle_key (key)
 Catch a key press and do the appropriate action. More...
 
def Vendotron.main ()
 Entry point for the Vendotron program. More...
 

Variables

dictionary Vendotron.drinks
 A dictionary of all drinks in the machine. More...
 

Detailed Description

Function Documentation

◆ display()

def Vendotron.display (   message)

Display a Vendotron message in a pretty format.

Parameters
messageThe message to be displayed

◆ get_change()

def Vendotron.get_change (   price,
  payment 
)

Calculate the change required based on a given payment.

Parameters
priceA price in USD, expressed as a real number divisible by 0.01
paymentA dictionary containing the amount of each denomination that was paid. Keys are the denomination value and Values are the frequency of said denomination.
Returns
A dictionary of the same form as payment containing exact change in the fewest possible number of items

◆ handle_key()

def Vendotron.handle_key (   key)

Catch a key press and do the appropriate action.

0-7: insert a currency of one of these denominations:

  • 0 - penny
  • 1 - nickle
  • 2 - dime
  • 3 - quarter
  • 4 - 1 dollar bill
  • 5 - 5 dollar bill
  • 6 - 10 dollar bill
  • 7 - 20 dollar bill c, p, s, d: select a drink from drinks e eject the current balance q terminate the program

◆ main()

def Vendotron.main ( )

Entry point for the Vendotron program.

Run the Vendotron program, first displaying a welcome message and then responding to user actions. If the user hasn't pressed any buttons in a while (30s), display a random slogan. For user actions see handle_key . Also accepts CTRL+c to terminate the program swiftly.

Variable Documentation

◆ drinks

dictionary Vendotron.drinks
Initial value:
1 = {'c': Drink('Cuke', 1.00),
2  'p': Drink('Popsi', 1.20),
3  's': Drink('Spryte', 0.85),
4  'd': Drink("Dr. Pupper", 1.10)}

A dictionary of all drinks in the machine.

Keys are the keyboard key that triggers this drink. Values are drink objects.