lundi 20 janvier 2020

Estimate pi, given that you have random (0,1) using python [closed]

I had code the following task but I got that error:

# Estimate pi, given that you have random (0,1)
#n are the number of point do we actually want
import numpy as np
def estimate_pi(n):
    num_points_circle = 0 # initalize how many points are in the circle
    num_points_total = 0 # meaning in the square
    for _ in range(n): # keep looping end times
        x = np.random.unifrom(0,1)
        y = np.random.uniform(0,1)
        distance = x**2 + y**2
        if distance <= 1:
            num_points_circle +=1 #if smaller, add one
        num_points_total +=1
    return 4 * num_points_circle/num_points_total

estimate_pi(100)

" AttributeError: module 'numpy.random' has no attribute 'unifrom'"

Any suggestions?




Aucun commentaire:

Enregistrer un commentaire