Home python TypeError: 'float' object is not callable help

TypeError: ‘float’ object is not callable help

Author

Date

Category

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)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions