I am making a simple calculator that, among other things, can provide the user with a formatted history of their previous computations.
print('Formmated as an equation')
for x in range(len(finalhistory)):
print(num1history(x) float(operationHistory(x)) num2history(x) ' = '
finalhistory(x))
print(' ')
return
When ever this is run though, I get an error saying:
Exception has occurred: TypeError
'list' object is not callable
File "MCT.py", line 34, in BH
print(num1history(x) operationHistory(x) num2history(x) ' = ' finalhistory(x))
Edit:
Should have clarified that the histories called are arrays. num1history
, num2history
, finalhistory
store float
values, and operationHistory
stores str
values.
CodePudding user response:
You index lists with square brackets
print('Formmated as an equation')
for x in range(len(finalhistory)):
print(f'{num1history[x]} {float(operationHistory[x])} {num2history[x]} =
{finalhistory[x]}')
print(' ')
return
You should also print with an f-string
CodePudding user response:
finalhistory
is a list. We can't call this like a function.
finalhistory(x)
-> is the error.
Same for num1history
, operationHistory
and num2history
You might intent to use finalhistory[x]
, num1history[x]
, operationHistory[x]
, num2history[x]
.
CodePudding user response:
As I can see from the code you are using a list and lists are not callable.
Solution:
Use finalhistory[x]
...similarly for other arrays