我正在制作一個簡單的計算器,除其他外,它可以為用戶提供他們以前計算的格式化歷史記錄。
print('Formmated as an equation')
for x in range(len(finalhistory)):
print(num1history(x) float(operationHistory(x)) num2history(x) ' = '
finalhistory(x))
print(' ')
return
但是,當它運行時,我收到一條錯誤訊息:
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))
編輯:
應該澄清所呼叫的歷史是陣列。num1history, num2history,finalhistory存盤float值,operationHistory并存str儲值。
uj5u.com熱心網友回復:
正如我從代碼中看到的,您使用的是串列,而串列是不可呼叫的。解決方案:finalhistory[x]對其他陣列類似地使用...
uj5u.com熱心網友回復:
你用方括號索引串列
print('Formmated as an equation')
for x in range(len(finalhistory)):
print(f'{num1history[x]} {float(operationHistory[x])} {num2history[x]} =
{finalhistory[x]}')
print(' ')
return
您還應該使用 f 字串列印
uj5u.com熱心網友回復:
finalhistory是一個串列。我們不能像函式一樣呼叫它。
finalhistory(x) -> 是錯誤。
相同num1history,operationHistory并且num2history
您可能打算使用finalhistory[x], num1history[x], operationHistory[x], num2history[x]。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/383646.html
