Open In App

Python Program to Find Area and Circumference of Circle

Last Updated : 13 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Python provides a simple yet powerful way to calculate the area and circumference of a circle using various mathematical formulas. In this article, we will explore the main logic behind these calculations and demonstrate two commonly used methods to find the area and circumference of a circle in Python.

Main Logic

The fundamental formulas for finding the area (A) and circumference (C) of a circle are as follows:

  1. Area of Circle (A): A = π * r^2, where π (pi) is a mathematical constant approximately equal to 3.14159, and r is the radius of the circle.
  2. Circumference of Circle (C): C = 2 * π * r, where π is the constant, and r is the radius.

Python Program To Find Area And Circumference Of Circle

Below, are the code examples of Python Program To Find the Area and Circumference Of the Circle.

  • Using User Input
  • Using Function

Find Area And Circumference Of Circle Using User Input

In this example, the below code calculates the area and circumference of a circle based on the user-input radius, using the math module for the mathematical constant pi. The results are then displayed to the user.

Python3




import math
 
# Taking radius input from the user
radius = float(input("Enter the radius of the circle: "))
 
# Calculating area and circumference
area = math.pi * radius**2
circumference = 2 * math.pi * radius
 
# Displaying the results
print(f"Area of the circle: {area}")
print(f"Circumference of the circle: {circumference}")


Output :

Enter the radius of the circle: 23
Area of the circle: 1661.9025137490005
Circumference of the circle: 144.51326206513048

Find Area And Circumference Of Circle Using Function

In this example, below code defines a function `calculate` that computes the area and circumference of a circle using a given or default radius. The function is then called with the default radius (1.0), and the results are displayed, showing the default area and circumference of the circle.

Python3




import math
 
# Function to calculate area and circumference with default radius
def calculate(radius=1.0):
    area = math.pi * radius**2
    circumference = 2 * math.pi * radius
    return area, circumference
 
# Example usage with default radius
default_area, default_circumference = calculate()
print(f"Default Area: {default_area}")
print(f"Default Circumference: {default_circumference}")


Output :

Default Area: 3.141592653589793
Default Circumference: 6.283185307179586

Conclusion

In the provided Python program, the user is prompted to input the radius of a circle. The program then calculates and displays both the area and circumference of the circle using the entered radius. The math module is employed to access the mathematical constant pi for accurate calculations



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads