pi with random number.py

This commit is contained in:
Mert Gör 🇹🇷 2023-05-29 16:42:17 +03:00
parent 5a764c24a2
commit 50db63ef4f
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9

View File

@ -0,0 +1,18 @@
import random
import math
def getpi(n):
count = 0
for i in range(n):
x = random.random()
y = random.random()
if math.sqrt(x ** 2 + y ** 2) < 1:
count += 1
return 4 * count / n
while True:
n = int(input('Bir sayı giriniz:'))
if n == 0:
break
pi = getpi(n)
print(pi)