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..
6 ответов
+ 4
Power of 0.5 is the same as square root Ala Pottra
+ 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.
+ 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
+ 2
Slick or floor division with //
- 1
where is the sqrt got executed
- 1
thankyou