Prompt. when I write this code
a = int (input ())
b = int (input ())
c = int (input ())
p = (a + b + c) / 2
S = p (p - a) (p - b) (p - c)
math.sqrt (S)
print (S)
throws TypeError: ‘float’ object is not callable
This is probably something simple, but I just can’t figure it out. Thanks in advance
Answer 1, authority 100%
Error in S = p (p - a) (p - b) (p - c)
p
contains a real value (float
)
A p (p - a)
syntax for calling an object as a function.
I think the correct code would be:
S = p * (p - a) * (p - b) * (p - c)
Answer 2, authority 20%
-
p (...)
– call object p as a function with an argument from parentheses -
p * (...)
– multiply p by the result of the expression in parentheses.
Answer 3
a = int (input ())
b = int (input ())
c = int (input ())
p = (a + b + c) / 2
S = (p * (p - a) * (p - b) * (p - c)) ** 0.5
# need to put multiplication signs
# root can be calculated as a number to the 1/2 power i.e. ** 0.5
print (S)