Oct-13-2020, 01:15 AM
Hi
My homework was to calculate pi using a loop and figure out the time it takes for 10^3,10^5, and 10^7 iterations. Im very stuck as this is what I have so
import numpy as np
import time
start=time.time()
n=1000*sum1=1
for i in range (1, n+1):
sum1=(sum+(((-1)*i)/((2*i)+1)))
stop=time.time()
elapsed_time=stop-start
print("The sum of series of 1000 iterations is",(4*sum1))
print("It took {:.1e} secs for {} iterations of the loop". format(elapsed_time,n))
***I repeated this code for 10^5 and 10^7 iterations***
It says there is an error on n=1000*sum... and it says "cant assign to opertor"
I need help fixing that and the code checked to see if its wrong or right
Thank you!!
My homework was to calculate pi using a loop and figure out the time it takes for 10^3,10^5, and 10^7 iterations. Im very stuck as this is what I have so
import numpy as np
import time
start=time.time()
n=1000*sum1=1
for i in range (1, n+1):
sum1=(sum+(((-1)*i)/((2*i)+1)))
stop=time.time()
elapsed_time=stop-start
print("The sum of series of 1000 iterations is",(4*sum1))
print("It took {:.1e} secs for {} iterations of the loop". format(elapsed_time,n))
***I repeated this code for 10^5 and 10^7 iterations***
It says there is an error on n=1000*sum... and it says "cant assign to opertor"
I need help fixing that and the code checked to see if its wrong or right
Thank you!!