0

can anybody explain

class TriangleArea: def __call__(self, a, b, c): p = (a + b + c) / 2 result = (p * (p - a) * (p - b) * (p - c)) ** 0.5 return result area = TriangleArea() print(area(3, 4, 5)) can anybody explain how this returns 6.0 and what are these '*' means .. I am stuck on magic methods and researching some materials myself to gain a grip of this..

23rd May 2020, 1:24 PM
Alapottra Chakma
Alapottra Chakma - avatar
6 ответов
+ 4
Power of 0.5 is the same as square root Ala Pottra
23rd May 2020, 1:38 PM
Jnn
Jnn - avatar
+ 3
* is multiply / is division (will output a float unless otherwise specified) If you dont want the .0, try: ... return round(result) But i would leave it, less error.
23rd May 2020, 1:31 PM
Slick
Slick - avatar
+ 3
p = 12/2 =6.0 result = (6.0 * 3.0 * 2.0 *1.0)**0.5 = 36.0**0.5 = sqrt(36.0) = 6.0 * is multiply and ** is power
23rd May 2020, 1:34 PM
Jnn
Jnn - avatar
+ 2
Slick or floor division with //
23rd May 2020, 1:35 PM
Jnn
Jnn - avatar
- 1
where is the sqrt got executed
23rd May 2020, 1:37 PM
Alapottra Chakma
Alapottra Chakma - avatar
- 1
thankyou
23rd May 2020, 1:40 PM
Alapottra Chakma
Alapottra Chakma - avatar