Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-016

Uniform Continuous PDF

Problem

Continuous uniform probability density on [a, b] evaluated at x.

f(x) = 1 / (b - a) when a <= x <= b, else 0.0. Return 0.0 when b <= a.

Test cases

case 1
in: [0,1,0.3]
expected: 1
case 2
in: [0,2,2]
expected: 0.5
case 3
in: [0,2,2.5]
expected: 0
case 4
in: [-1,1,0]
expected: 0.5
case 5
in: [1,1,1]
expected: 0
Starter codePython
def uniform_continuous_pdf(a, b, x):
    # Your code here
    pass

5 test cases · run your code against them in the editor