Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from prettytable import PrettyTable
- data = [{
- 'purchase_price': 26,
- 'amount_purchased': 20,
- 'amount_sold': 13,
- 'sold_for': 3000
- },{
- 'purchase_price': 26,
- 'amount_purchased': 116,
- 'amount_sold': 26,
- 'sold_for': 30000
- },{
- 'purchase_price': 26,
- 'amount_purchased': 116,
- 'amount_sold': 52,
- 'sold_for': 100000
- }]
- profit = 0
- carryover_amount = 0
- current_amount = 0
- bank = 0
- t = PrettyTable(['Inventory', 'Profit', 'Carryover', 'Bank'])
- t.align["Inventory"] = "r"
- t.align["Profit"] = "r"
- t.align["Carryover"] = "r"
- t.align["Bank"] = "r"
- for d in data:
- profit = (d['sold_for']) - (d['purchase_price'] * d['amount_purchased'])
- bank = bank + profit
- carryover_amount = (d['amount_purchased'] - d['amount_sold'])
- current_amount = current_amount + carryover_amount
- t.add_row(['{:,}'.format(current_amount),
- '${:,.2f}'.format(profit),
- '{:,}'.format(carryover_amount),
- '${:,.2f}'.format(bank)])
- print t
Add Comment
Please, Sign In to add comment