Python无法描述两个变量

时间:2019-04-24 21:30:29

标签: python string math

我正在尝试制作一个简单的程序来计算三角形的面积。 但是最后,python无法识别我正在使用的str函数。我几乎没有Python经验,所以如果这是一个愚蠢的问题,那就是为什么。

我尝试重命名变量并查看Stack Overflow上的其他问题。没有任何帮助

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)

但是Python终端(repl)带回了

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

1 个答案:

答案 0 :(得分:0)

这是一个答案,所有功劳归功于Barmar,后者首先发表了包含答案的评论。 TheFriendlyPythonGuy,请接受此答案以结束问题。这是您的代码应如下所示:

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)
相关问题