I have the following code which i want to execute :
import math
class A(object):
def someNum(self, num):
num = int(math.log2(num))
return num
a = A()
a.someNum('9')
But it throws an exception :
Traceback (most recent call last):
File "main.py", line 34, in <module>
a.numToLoc('9')
File "main.py", line 30, in numToLoc
num = int(math.log2(num))
AttributeError: 'module' object has no attribute 'log2'
What am i missing ?
math.log2()was added in Python 3.3; you're apparently using an older version. Trymath.log(num, 2)instead.somenum(). I think you want to pass an integer instead:a.someNum(9)