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

19 lines
340 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)