Q:

sum of cubes using formula

Given
\sum_{k=0}^{n}k^3 = \frac{n^2(n+1)^2}{4}

I need to compute the left hand side. I should make a list of the first 1000 integer cubes and sum them. 
Then I should compute the right hand side and to the same. 
Also, I am supposed to compare the computational time for the above methods. 
What I've done so far is:
import time 
start = time.clock()

list = []
for n in range(0,1001):
    list.append(n**3)
print(list)
print("List of the first 1000 integer cubes is:",list, "and their sum is:", sum(list))

stop = time.clock() 
print("Computation time: ",stop-start, "seconds.")

a=0
for n in range (0,1001):
    a=(int)(n*(n+1)/2)
print ("Sum of the first 1000 integer cubes is:",a*a)

First part for the left hand side works fine, but the problem is the right hand side. 
When I type n=4, I will get the same result for the both sides, but problem occurs when n is big, because I get that one side is bigger than the other, i.e. they are not same. 
Also, can you help me create a list for the right hand side, I've tried doing something like this:
a=[]
for n in range (0,10):
    a.append(int)(n**2(n+1)**2/4)

But it doesn't work. 
For the computational time, I think I am supposed to set one more timer for the right hand side, but then again I am not sure how to compare them.
Any advice is welcome,

A:

Ok, I think what you tried in a for loop is completely wrong. If you want to prove the formula "the hard way" (non-inductive way it is) - you need to simply sum cubes of n first integers and compare it against your formula - calculated one time (not summed n times). 
So evaluate:
n=100
s=0
for i in range(1,n+1):
    s+=i**3
###range evaluates from 1 till n if you specify it till n+1
s_ind=(n**2)*((n+1)**2)/4

print(s==s_ind)

Otherwise if you are supposed to use induction - it's all on paper i.e. base condition a_1=1^3=((1)*(2)^2)/4=1 and step condition i.e. a_n-a_(n-1)=sum(i^3)[i=1,...,n]-sum(j^3)[i=1,...,n-1]=n^3 (and that it also holds assuming a_n=your formula here (which spoiler alert - it does ;) )
Hope this helps.

