Apr-22-2019, 02:39 AM
Dear Collegues,
Thank you in advance for your help. My code is not generating the profitability of this calculation:
Current Value - Purchase Price X No of Shares for my Dictionary.
Any support is highly appreciated!
Thank you in advance for your help. My code is not generating the profitability of this calculation:
Current Value - Purchase Price X No of Shares for my Dictionary.
Any support is highly appreciated!
mydata = {'Stock1': [125, 772.88, 941.53], 'Stock2': [85, 56.60, 73.04], 'Stock3': [400, 49.58, 55.74], 'Stock4': [235, 54.21, 65.27], 'Stock5': [150, 124.31, 172.45]} headers = ["Stock Symbol", "No Shares", "Purchase Price", "Current Value"] headers1 = ["Stock Symbol", "No Shares", "Earnings/Loss"] separator1 = '+----------------+-------------+------------------+-----------------+' separator2 = '+================+=============+==================+=================+' print("\nStock Earnings/Losses ") print(separator1) print('| {:14} | {:11} | {:15} |'.format(*headers1)) print(separator2) for element in mydata: s = (element[3] - element[2]) * element[1] print('| {:14} | {:11} | ${:14,.2f} |'.format(element[0], element[1], s)) print(separator2)
Output:Traceback (most recent call last):
File "<input>", line 18, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Stock Earnings/Losses
+----------------+-------------+------------------+-----------------+
| Stock Symbol | No Shares | Earnings/Loss |
+================+=============+==================+=================+