Guest User

Untitled

a guest
Dec 10th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. from prettytable import PrettyTable
  2.  
  3. data = [{
  4. 'purchase_price': 26,
  5. 'amount_purchased': 20,
  6. 'amount_sold': 13,
  7. 'sold_for': 3000
  8. },{
  9. 'purchase_price': 26,
  10. 'amount_purchased': 116,
  11. 'amount_sold': 26,
  12. 'sold_for': 30000
  13. },{
  14. 'purchase_price': 26,
  15. 'amount_purchased': 116,
  16. 'amount_sold': 52,
  17. 'sold_for': 100000
  18. }]
  19.  
  20.  
  21. profit = 0
  22. carryover_amount = 0
  23. current_amount = 0
  24. bank = 0
  25.  
  26. t = PrettyTable(['Inventory', 'Profit', 'Carryover', 'Bank'])
  27. t.align["Inventory"] = "r"
  28. t.align["Profit"] = "r"
  29. t.align["Carryover"] = "r"
  30. t.align["Bank"] = "r"
  31.  
  32. for d in data:
  33. profit = (d['sold_for']) - (d['purchase_price'] * d['amount_purchased'])
  34. bank = bank + profit
  35. carryover_amount = (d['amount_purchased'] - d['amount_sold'])
  36. current_amount = current_amount + carryover_amount
  37.  
  38. t.add_row(['{:,}'.format(current_amount),
  39. '${:,.2f}'.format(profit),
  40. '{:,}'.format(carryover_amount),
  41. '${:,.2f}'.format(bank)])
  42.  
  43. print t
Add Comment
Please, Sign In to add comment