What is the time complexity of this algorithm?
In Python, range(0,n) iterates through the values 0, 1, 2, .., n-1 (but not n).  Therefore, your summation should have been

$$\sum_{i=0}^{n-1} \cdots$$

rather than

$$\sum_{i=1}^{n} \cdots$$

and similarly for the other sums as well.