2013-05-06 75 views
0

我不斷收到類型錯誤:「浮動」對象未標化的 想知道爲什麼類型錯誤:「浮動」對象未標化的Python 3

from math import log 

class Logarithm(object): 

    def __init__(self, base = 0, number= 0): 
     self.base = float(base) 
     self.number = float(number) 

     the_logarithm = log(self.base[self.number]) 

    def __str__(self): 
     return 'Your log = {}'.format(the_logarithm) 
+0

也,它應該是'self.the_logarithm'(均在'__init__'和'__str__' )。 – nvlass 2013-05-06 23:09:04

回答

2

正因爲如此:

log(self.base[self.number]) 

你是什麼試圖在這裏完成? self.base是一個浮點數,因此該語句被評估爲「base」的number th元素,Python不能這樣做。

2

Cameron Sparr的回答是正確的。

您應該重新檢查help(math.log)。 它是

log(x[, base]) -> the logarithm of x to the given base. 

這意味着鹼參數是可選的(默認爲e) 和不log(x[base])

相關問題