首页 > 编程知识 正文

Python 程序:计算菱形面积

时间:2023-11-25 09:12:54 阅读:309017 作者:OCSM

写一个 Python 程序,用一个例子找到菱形的面积。这个 Python 示例允许菱形第一和第二对角线,并计算菱形面积。

# Python Program to find Rhombus Area

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 程序中,我们创建了一个 cal 菱形面积函数来寻找菱形面积。

# Python Program to find Rhombus Area

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) 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。