If a, b and c are three sides of a triangle. Then, s = (a+b+c)/2 area = √(s(s-a)*(s-b)*(s-c)) Source Code
Output The area of the triangle is 14.70 In this program, area of the triangle is calculated when three sides are given using Heron's formula. If you need to calculate area of a triangle depending upon the input from the user, input() function can be used. Triangular Numbers are those numbers which are obtained by continued summation of the natural numbers 1, 2, 3, 4, 5, ... Triangular Number Example: 15 is Triangular Number
because it can be obtained by 1+2+3+4+5+6 i.e. 1+2+3+4+5+6=15 List of Triangular Numbers: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528, 561, 595, 630, 666, Also try: Check Triangular Number Online &
Generate Triangular Numbers Online Full name random.triangular Syntax random.triangular(low, high [, mode]) Description The random.triangular function returns a random number N drawn from a triangular distribution such that low <= N <= high, with the mode specified in the third argument, mode. If the mode argument is not specified, it defaults to the value (low + high) / 2, that is, the value located at the midpoint of the range considered. Parameters
Result The random.triangular function returns a real number. Examples We can generate a random number in the range [10.0, 15.0] extracted from a triangular distribution with a default mode equal to 12.5 with the following code: random.triangular(10, 15) 14.034414418629337 We could repeat the previous example forcing a mode equal to 14 with the following code: random.triangular(10, 15, 14) 11.991174889023462 To confirm the distribution from which the random numbers are extracted we can generate 10 thousand random numbers in the range [10.0, 15.0] with default mode and show its histogram: import matplotlib.pyplot as plt plt.figure(figsize
= (8, 4)) If we repeat the previous example setting the value 14 as mode, we obtain the following result: plt.figure(figsize = (8, 4)) Draw samples from the triangular distribution over the interval The triangular distribution is a continuous probability distribution with lower limit left, peak at mode, and upper limit right. Unlike the other distributions, these parameters directly define the shape of the pdf. Note New code should use the Lower limit. The value where the peak of the distribution occurs. The value must fulfill the condition Upper limit, must be larger than left. sizeint or tuple of ints, optionalOutput shape. If the given shape is, e.g., Drawn samples from the parameterized triangular distribution. Notes The probability density function for the triangular distribution is \[\begin{split}P(x;l, m, r) = \begin{cases} \frac{2(x-l)}{(r-l)(m-l)}& \text{for $l \leq x \leq m$},\\ \frac{2(r-x)}{(r-l)(r-m)}& \text{for $m \leq x \leq r$},\\ 0& \text{otherwise}. \end{cases}\end{split}\] The triangular distribution is often used in ill-defined problems where the underlying distribution is not known, but some knowledge of the limits and mode exists. Often it is used in simulations. References 1Wikipedia, “Triangular distribution” https://en.wikipedia.org/wiki/Triangular_distribution Examples Draw values from the distribution and plot the histogram: >>> import matplotlib.pyplot as plt >>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200, ... density=True) >>> plt.show() |