We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2db28d commit 5f2996fCopy full SHA for 5f2996f
openSAP/exercise-bonus-week6.py
@@ -1,11 +1,9 @@
1
-import math
2
-import random
+from math import pi
+from random import random
3
4
-points_in_square = [(random.random(), random.random()) for _ in range(10000)]
5
-count_in_circle = len([(x, y) for x, y in points_in_square if x * x + y * y < 1])
6
-my_pi = count_in_circle / len(points_in_square) * 4
+my_pi = len([True for _ in range(10000) if random() ** 2 + random() ** 2 < 1]) / 10000 * 4
7
8
print(f'Calculated value of π: {my_pi}')
9
10
-print(f'Value of π from math library: {math.pi}')
11
-print(f'Difference: {abs(math.pi - my_pi)}')
+print(f'Value of π from math library: {pi}')
+print(f'Difference: {abs(pi - my_pi)}')
0 commit comments