我是Python的初学者,正在尝试计算三角形的面积。这个任务要求定义area函数,我无法让它返回一个有效值(应该是float)给main函数。
from math import sqrt
def area(linea, lineb, linec):
"""function is supposed to find the area of the triangle"""
s = (linea + lineb + linec) // 2
a = sqrt(s * (s - linea) * (s - lineb) * (s - linec))
return a
def main():
linea = float(input("Enter the length of the first side: "))
lineb = float(input("Enter the length of the second side: "))
linec = float(input("Enter the length of the third side: "))
b = float(a)
print("The triangle's area is %0.2f" %b)
打印应该给出0.0形式的面积。我该怎么做才能不得到错误代码"NameError: domainname, 'a',深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切,深切"?
我试了你的代码。简单地说,我想你指的是下面这行代码:
b = float(a)
:
b = float(area(linea, lineb, linec))
致意。