From ab3400bfad35f91756ef88e1b53f8865afc09a75 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 14 Mar 2020 23:55:13 +0100 Subject: [PATCH] Travis CI: Fix Travis linter errors (#1802) * Travis CI: Fix Travis linter errors * fixup! Format Python code with psf/black push * Update .travis.yml * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> --- .travis.yml | 2 ++ DIRECTORY.md | 1 + maths/pi_monte_carlo_estimation.py | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aec411c52..b9c47c179 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +os: linux +dist: bionic language: python python: 3.8 cache: pip diff --git a/DIRECTORY.md b/DIRECTORY.md index 8dd9fa929..121b4df17 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -321,6 +321,7 @@ * [Newton Raphson](https://github.com/TheAlgorithms/Python/blob/master/maths/newton_raphson.py) * [Numerical Integration](https://github.com/TheAlgorithms/Python/blob/master/maths/numerical_integration.py) * [Perfect Square](https://github.com/TheAlgorithms/Python/blob/master/maths/perfect_square.py) + * [Pi Monte Carlo Estimation](https://github.com/TheAlgorithms/Python/blob/master/maths/pi_monte_carlo_estimation.py) * [Polynomial Evaluation](https://github.com/TheAlgorithms/Python/blob/master/maths/polynomial_evaluation.py) * [Prime Check](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_check.py) * [Prime Factors](https://github.com/TheAlgorithms/Python/blob/master/maths/prime_factors.py) diff --git a/maths/pi_monte_carlo_estimation.py b/maths/pi_monte_carlo_estimation.py index 7f341ade9..d91c034cc 100644 --- a/maths/pi_monte_carlo_estimation.py +++ b/maths/pi_monte_carlo_estimation.py @@ -18,7 +18,8 @@ class Point: """ Generates a point randomly drawn from the unit square [0, 1) x [0, 1). """ - return cls(x = random.random(), y = random.random()) + return cls(x=random.random(), y=random.random()) + def estimate_pi(number_of_simulations: int) -> float: """ @@ -56,6 +57,7 @@ if __name__ == "__main__": # doctest.testmod() from math import pi + prompt = "Please enter the desired number of Monte Carlo simulations: " my_pi = estimate_pi(int(input(prompt).strip())) print(f"An estimate of PI is {my_pi} with an error of {abs(my_pi - pi)}")