Python 計算圓的面積

Document 對象參考手冊 Python3 實例

圓的面積公式為 :

公式中 r 為圓的半徑。

實例

# 定義一個方法來計算圓的面積
def findArea(r):
    PI = 3.142
    return PI * (r*r)
 
# 調用方法
print("圓的面積為 %.6f" % findArea(5))

以上實例輸出結果為:

圓的面積為 78.550000

Document 對象參考手冊 Python3 實例