# Python Logarithm, Value Error : math domain error

### 3 Answers

The range(n) is from 0 to n-1 But Log(0) is not defined hence use range(1,n) instead.

Monith Shah
posted this

```
import math
n = 1000000
n2 = 0
for i in range(1,n):
x = math.log2(i)
n2 += x
print(n2)
```

happy codeing !

soheshdoshi
posted this

## Have an answer?

JD

You are calculating

`log2(0)`

, which is`- inf`

. Hence you are getting the error. Try`range(1,n)`

.