import random def main(): sum = 1000000 sum_in = 0 for i in xrange(0,sum): x = random.random() y = random.random() if (x-0.5)*(x-0.5)+(y-0.5)*(y-0.5)<=0.25: sum_in = sum_in+1 print('%s/%s = %s'%(sum_in,sum,float(sum_in)/sum)) print('PI = %s'%(4*float(sum_in)/sum)) if __name__=='__main__': main()
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课