Coding/Python 삽질기2010. 7. 9. 01:14
import random
 
 
total = 100
 
for idx in range (1, 7):
    total *= 10
    in_count = 0;
    
    for i in range (1, total):
        x = random.random()
        y = random.random()
   
        if (x * x + y * y <= 1):
            in_count += 1
       
    print "Run %d : %f" %(total, in_count * 4.0 / total)


 

Run 1000 : 3.092000
Run 10000 : 3.124400
Run 100000 : 3.141120
Run 1000000 : 3.139376
Run 10000000 : 3.141186
Run 100000000 : 3.141469


'Coding > Python 삽질기' 카테고리의 다른 글

Self number  (1) 2010.07.10
100!  (0) 2010.07.08
Quick Sort  (0) 2010.06.10
Posted by chobocho