find the area of a circle in python

To find the area of a circle in Python, we need to use the formula:

Area = pi * r^2

where pi is a mathematical constant (3.14159...) and r is the radius of the circle.

Here's how you can calculate the area of a circle in Python:

main.py
import math

radius = 5
area = math.pi * (radius ** 2)

print("The area of the circle is:", area)
98 chars
7 lines

In this example, we first import the math module, which provides access to mathematical functions like pi. We then define the radius of the circle as 5, and use the formula to calculate the area. Finally, we print out the calculated area using the print() function.

The output of this code will be:

main.py
The area of the circle is: 78.53981633974483
45 chars
2 lines

related categories

gistlibby LogSnag