pi with random number.py
This commit is contained in:
parent
5a764c24a2
commit
50db63ef4f
18
python-temel/pi.random.number.py
Normal file
18
python-temel/pi.random.number.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user