我試圖在數學上演示蒙特卡洛方法,但我總是得到 0。我已經試過把 sci=sci+1,import randomimport mathimport timeprint("generando")sci=0for i in range(30): x = random.random() y = random.random() if (x<x*x)and(y<=y*y) :#probably imposible to reach(?) sci += 1 #probably the error time.sleep(0.001)scu=ir=(4*sci)/scu它實際上需要給出一個接近 pi 的數字,當你增加 for 的范圍時會更準確。
添加回答
舉報
0/150
提交
取消