Last active
September 7, 2021 09:26
-
-
Save ecklf/a1eab45c3fc209756b3a to your computer and use it in GitHub Desktop.
A simple script to calculate pi with random generated numbers using python3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'ecklf' | |
# IMPORT | |
import random | |
# VAR | |
random.seed() | |
radius = 424242 | |
loops = 10000 | |
counter = 0 | |
pi = 0.0 | |
# DEF | |
def power(var): | |
return var**2 | |
# FUNC | |
for i in range(0, loops): | |
x = random.randint(1, radius) | |
y = random.randint(1, radius) | |
if (power(x)+power(y)) < power(radius): | |
counter += 1 | |
pi = 4.0 * counter / loops | |
print(str(counter) + " of " + str(loops) + " points were located in the circle district") | |
print(pi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment