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
JavaScript
x
9
1
promt = input ("Type square or quadrilateral : ")
2
if promt == "square" :
3
print ("Square has been chosen")
4
#s stands for square and t stands for triangle
5
sbase = input ("Type the base : ")
6
sheight = input ("Type the height : ")
7
sfinal = sbase(str)*sheight(str)
8
print (sfinal)
9
But the Python terminal (repl) brings back
JavaScript
1
5
1
Traceback (most recent call last):
2
File "main.py", line 7, in <module>
3
sfinal = sbase(str)*sheight(str)
4
TypeError: 'str' object is not callable
5
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:
JavaScript
1
9
1
promt = input ("Type square or quadrilateral : ")
2
if promt == "square" :
3
print ("Square has been chosen")
4
#s stands for square and t stands for triangle
5
sbase = input ("Type the base : ")
6
sheight = input ("Type the height : ")
7
sfinal = int(sbase)*int(sheight)
8
print (sfinal)
9