MathProbabilityProbabilistic modeling

Probabilities as frequencies

Triangle

Report a typo

A rod of length 1 meter was randomly cut in two places so that three pieces were obtained. The following code generates the length of these pieces in meters:

def lengths_of_pieces():
    # In the topic, we did not discuss the random.uniform method
    # Treat it just like a black box that returns reals between 0 and 1
    first_cut = random.uniform(0, 1)
    second_cut = random.uniform(0, 1)
    left_piece = min(first_cut, second_cut)
    right_piece = 1 - max(first_cut, second_cut)
    middle_piece = 1 - left_piece - right_piece
    return left_piece, middle_piece, right_piece

Using 10,000 repetitions, estimate the probability that these pieces can form a triangle.

Enter a number
___

Create a free account to access the full topic