Click here to Skip to main content
14,869,895 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
X is a standard normal random variable N(0,1). Write a piece of code to compute the probability P(-0.3<x<2.1). your code should print out the probability, rounded to 6 decimal places.

What I have tried:

Python
x = np.linspace(-0.3,2.1)
prob1 = stats.norm.cdf(x,loc=0,scale=1)
output=round(prob,6)
print(output)
Posted
Updated 23-Mar-21 5:34am
v2
Comments
Richard MacCutchan 23-Mar-21 11:16am
   
So what is the question?

1 solution

I would write it this way
Python
from scipy.stats import norm
prob0 = norm.cdf(-0.3)
prob1 = norm.cdf(2.1)
output=round((prob1-prob0), 6)
print(output)
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900