My professor has tasked us with finding pi with Python.
This is the psudocode we are using as a reference:
'''pseudocode
square of area 4 i.e. side length 2 centered at (0,0)
inscribed circle of radius 1, centered at (0,0)
area of square = 4, area of circle = pi
pi = (area of circle/ area of square) *4'''
Absolutely no one in my class has any prior programming experience, and I was hoping for any possible help for newbies.
>>17094431
import math
math.pi
>>17094445
I already know about math.pi, but our teacher wants us to find it using rng and a circle in a square.
>>17094431
I'm not going to do your homework for you, but aren't you just calculating the ratio of the circle to the square? since the square has bilateral symmetry and the circle is inscribed, you can set up an iterative loop using rng to converge on the answer. You only need to use on quadrant to make the program slightly more efficient, but it is still not the best solution.
And this exercise is a brief intro to Monte Carlo technique.
>>17094431
Just use Monte Carlo, dumbass.
It should be something like this.
Count=0
Picount=0
For i=1:1000000
X=rand()
Y=rand()
If(X^2+y^2<=1)
Picount++
End
End
Pi=4*picount/count
>>17094742
Couldn't you have posted something fake, for christssake. This is why people like OP are mentally lazy and will one day end up working on missile telemetry or something, which will come back to fuck us all over.
>>17094632
How am I to use something I have never heard of? It is for a highschool class in a school where we are just starting to get computer classes.
>>17094813
You're supposed to try. You're supposed to think. "This is new" isn't an excuse. Draw the circle and the square. Think how you would do it if you didn't have to do it using Python, but a bunch of random darts (random mum generator).
Are you from the U.S.? (Please say no...)