Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Caluculating pi using loops
#1
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!!
Reply
#2
What do you intend for that line to accomplish?  What is the =1 at the end of that line supposed to do?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020