Home >Backend Development >Python Tutorial >python calculate area of ​​circle

python calculate area of ​​circle

silencement
silencementOriginal
2019-06-05 11:41:1550187browse

python calculate area of ​​circle

How to calculate the area of ​​a circle using python?

First of all, we need to know the formula for calculating the area of ​​a circle: S = πr². In the formula, S is the area of ​​the circle required, π is the pi ratio, and r is the radius of the circle.

Example

# 定义一个方法来计算圆的面积
def findArea(r): 
    PI = 3.142
    return PI * (r*r); 
  
# 调用方法
print("圆的面积为 %.6f" % findArea(5));

In the above example we defined a findArea() function, the parameter r is the radius of the circle, the pi is 3.142, and the return value of the function is PI * (r *r), which is the area of ​​the circle.

For more python related technical articles, please visit python tutorial to learn.

The above is the detailed content of python calculate area of ​​circle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn