__author__ = 'jsgreenwell' import POSFunctions #our custom class from collections import OrderedDict """Basic change making program using 100 base (American Currency): will create full knapsack version in later example. This example will also be expanded, in steps, until it becomes a simple OO-based (ie. we'll add classes) POS system with database tie-in and GUI UI. This version just adds a very basic commandline UI that will eventually be replaced by database and POS (tk) system. It also imports a custom class for handling POS Functions. """ StoreInventory = { 132: {"name": "banana", "price": .56, "qoh": 10}, 333: {"name": "fish", "price": 4.56, "qoh": 3}, 378: {"name": "frozen dinner", "price": 7.59, "qoh": 20}, 388: {"name": "beef", "price": 4.98, "qoh": 8}, 908: {"name": "peas", "price": 2.98, "qoh": 11} } #not the best method for this; Only for testing before database creation def display_inventory(): """ Displays the inventory in a semi-formatted fashion. Print will be replaced by GTK display then a database call will be added. Using a simple for range of 0-4 is a good method of displaying matching keys and values when the values are equal sized keys :return: void """ print "Inventory Display\n ID | NAME | PRICE | QOH " for id in OrderedDict(sorted(StoreInventory.items(), key=lambda t: t[0])): print '{0:^5}|{1:^14}|{2:^7}| {3}'.format(id, StoreInventory[id]["name"], StoreInventory[id]["price"], StoreInventory[id]["qoh"]) # 0:^5 = first passed arg:(center) padding of 5 spaces def main(): """ Main here includes a lot of the actual processing, this is both just due to us testing and because that's just how it is sometimes. Create working code first, optimize later - means that sometimes programmers will not have time to separate the logic the way they might eventually want to. This can also be on purpose if the program is small or only performs one or two functions. """ pos = POSFunctions.RegisterFunctions(123432) #Just sending a random number as sale rep ID for now item_id = 0 purchased_qty = 0 display_inventory() while item_id != 999: # TODO: Add Error checking and input valuidation (ie. ID exists, qty is available) item_id = int(raw_input("Enter the Item ID Number (999 to exit): ")) if item_id != 999: purchased_qty = int(raw_input("Enter the Quantity Purchased: ")) pos.addpurchase(item_id, StoreInventory[item_id]["name"], purchased_qty, StoreInventory[item_id]["price"]) StoreInventory[item_id]["qoh"] -= purchased_qty print "Your Total Price is ${0:.2f}".format(pos.calctotalsale()) """ There is an error that sometimes occurs here (you might see it) where the change due is sometimes +/- .01 off between the total here and the calculated change later. This is due to a floating point rounding error and it will be covered later (when numpy is introduced). For now just be aware of it. """ while pos.total > pos.payment: pos.addpayment(float(raw_input("Please enter a payment amount: "))) #Should error check then pass print pos.getchange() main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question