寫一個 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)
原創文章,作者:DLKMX,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/317760.html