Program for interactive virtual vending machine. More...
Functions | |
| def | vendotron.kb_cb (key) |
| Callback method based on keyboard inputs. More... | |
| def | vendotron.getCents (moneyDict) |
| Function for determining monetary value of a set of denominations. More... | |
| def | vendotron.getChange (price, payment, debugFlag) |
| Function for determining least change for a set of denominations. More... | |
| def | vendotron.VendotronTask (debugFlag, idleTime) |
| Generator function to run the main finite state machine. More... | |
Variables | |
| def | vendotron.vendo = VendotronTask(debugFlag = False, idleTime = 15 ) |
| Instance of generator/task. More... | |
| list | vendotron.callbackKeys = ['0','1','2','3','4','5','6','7','e','c','p','s','d','q'] |
| List containing all keys used as callbacks. | |
| vendotron.lastKey = None | |
The last key released on the keyboard (must be a member of the list callbackKeys) | |
Program for interactive virtual vending machine.
This file contains code for a virtual vending machine. Its general functionality includes the following:
See source code here: https://bitbucket.org/ryanmclaug/me_405/src/master/Lab0x01/vendotron.py
| def vendotron.getCents | ( | moneyDict | ) |
Function for determining monetary value of a set of denominations.
This function utilizes the .items() method for dictionary objects, to loop through pairs of denomination values and quantities.
| moneyDict | is a dictionary containing the current set of denominations to be counted |
| def vendotron.getChange | ( | price, | |
| payment, | |||
| debugFlag | |||
| ) |
Function for determining least change for a set of denominations.
This function was first developed in HW0x01, and improved upon for use in the larger lab assigment of the vending machine. Given a set of denominations, the function must be able to determine the resulting change in the least number of denominations. If the payment is not sufficient, the function must recognize this and give a useful output.
| price | is the price in cents of the item to be purchased |
| payment | is a dictionary of denominations and their respective quantities |
| debugFlag | is a input to the overall generator set to True when debugging code |
change can be one of two things: if the payment exceeds or matches the price, change is a dictionary contatining the least change, and if the payment is not enough for the given price, change is set to None. | def vendotron.kb_cb | ( | key | ) |
Callback method based on keyboard inputs.
In order to use the keyboard to set certain tasks into motion, a callback is used, along with the keyboard module for python.
| key | is the key released by the user |
| def vendotron.VendotronTask | ( | debugFlag, | |
| idleTime | |||
| ) |
Generator function to run the main finite state machine.
Each time the next() function is called for this function from within the "main script" of this file, the generator runs one iteration of the finite state machine, and yields the next state for the upcoming iteration.
| debugFlag | is used to relay more information to the console while in the program development phase |
| idleTime | is the maximum allowable time without user action before a "scroll message" is displayed in the console |
state is yielded each time next() is called, and is the state corresponding to the starting point of the next iteration | def vendotron.vendo = VendotronTask(debugFlag = False, idleTime = 15 ) |
Instance of generator/task.
Although this program does not utilize a class structure, it does use an object based structure. In this case, vendo is an instance of the function/generator VendtronTask which contains the main finite state machine for the file.