python-CSD-kursu/python-temel/pi.random.number.py

19 lines
340 B
Python
Raw Normal View History

2023-05-29 16:42:17 +03:00
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)