编写一个 Python 程序,通过示例查找菱形的面积。此示例允许输入菱形的对角线长度,并计算菱形的面积。
rhombusD1 = float(input("Enter Rhombus First Diagonal = "))
rhombusD2 = float(input("Enter Rhombus Second Diagonal = "))
rhombusArea = (rhombusD1 * rhombusD2)/2
print("The Area of a Rhombus = %.3f" %rhombusArea)
菱形面积输出
Enter Rhombus First Diagonal = 25
Enter Rhombus Second Diagonal = 28
The Area of a Rhombus = 350.000
在此 Python 程序中,我们创建了一个 calRhombusArea 函数来查找菱形的面积。
def calRhombusArea(d1, d2):
return (d1 * d2)/2
rhombusD1 = float(input("Enter Rhombus First Diagonal = "))
rhombusD2 = float(input("Enter Rhombus Second Diagonal = "))
rhombusArea = calRhombusArea(rhombusD1, rhombusD2)
print("The Area of a Rhombus = %.3f" %rhombusArea)
