Site icon TestingDocs.com

Python Program : Area of a Circle

Overview

In this tutorial, let’s write a simple Python program to find the area of a circle. First, to write this program, we should know the formula to calculate the area of a circle.

We will use the Python IDLE code editor on the Windows operating system.

Area of  a Circle

The mathematical formula to compute the area is as follows:

area = pi* r^2 

or 

pi * r * r

 

where r = is the circle’s radius, we need to read the value of ‘r’ from the user.

Program

Python program to find the area of a circle. Create a new file using the menu option File -> New File and Save the program in a file with a .py file extension.

# Python Program Area of Circle
# Python Tutorials – www.TestingDocs.com

import math

# Take user input for the radius
r = float(input(‘Enter the radius := ‘))

# Compute Area of the Circle
area = math.pi *( r **2 )

# Print area
print(‘Area of the Circle := ‘, area)

Program Output 

Run the program to view the output.

Sample output of the program is as follows:

Enter the radius := 10
Area of the Circle := 314.1592653589793

 

This program uses the math.pi constant for the value of π and takes user input for the circle’s radius. It then calculates the area using the provided formula and prints the result.

Python Tutorials

Python Tutorial on this website can be found at:

https://www.testingdocs.com/python-tutorials/

More information on Python is available at the official website:

https://www.python.org

Exit mobile version