0

Math statistics with python

You have a stick, if you break it in 2 parts and then you break one of them in another 2 parts what's the probability to form a triangle. Can someone show me how would look the python program for this problem?

29th Dec 2021, 2:18 PM
Zotta
Zotta - avatar
2 Respuestas
0
Maybe you wish to write a simulator to determine probability by using the Monte Carlo technique - that is, trying many random solutions and aggregating the results. Loop a number of trials as follows: 1. Get a random number within a certain range, say 0 to 100. That will represent where the first break is made of a 100-unit-long stick. Now you have two pieces of known length. If both pieces are the same length (50), or if a piece is either 0 or 100, then mark this trial as a failure and exit to start the next one. 2. Randomly select one piece or the other by using a random integer selection, say betwixt 0 or 1. 3. If the selected piece is the shorter piece then mark this trial as a failure and exit this trial to start the next one. 4. Get another random number from 0 to the selected piece length to divide where the selected piece gets broken. 5. If all pieces are less than half the original length then mark this trial as a success, else mark it as a failure. 6. Exit to start the next trial.
29th Dec 2021, 5:08 PM
Brian
Brian - avatar