Skip to content
Advertisement

Python can’t describe two varibles

I am trying to make a simple program to calculate the area of a triangle. But at the end, python does not recognize the str function I am using. I have little to no experience on Python so if this is a stupid question, then that is why.

I have tried renaming the variables and looking at other questions on Stack Overflow. None really helped

promt = input ("Type square or quadrilateral : ")
if promt == "square" :
  print ("Square has been chosen")
  #s stands for square and t stands for triangle
  sbase = input ("Type the base : ")
  sheight = input ("Type the height : ")
  sfinal = sbase(str)*sheight(str)
  print (sfinal)

But the Python terminal (repl) brings back

Traceback (most recent call last):
  File "main.py", line 7, in <module>
    sfinal = sbase(str)*sheight(str)
TypeError: 'str' object is not callable

Advertisement

Answer

Here is an answer, all credit goes to Barmar, who first made a comment containing the answer.

Here is what your code should look like:

promt = input ("Type square or quadrilateral : ")
if promt == "square" :
  print ("Square has been chosen")
  #s stands for square and t stands for triangle
  sbase = input ("Type the base : ")
  sheight = input ("Type the height : ")
  sfinal = int(sbase)*int(sheight)
  print (sfinal)
Advertisement