[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Attention tech nerds
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /adv/ - Advice

Thread replies: 10
Thread images: 1
File: python logo.png (14 KB, 121x121) Image search: [Google]
python logo.png
14 KB, 121x121
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
>>
>>>/g/
>>
>>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...)
Thread replies: 10
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.