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

Attention tech nerds

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 10
Thread images: 1

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


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.