How to find circumference of circle with Python?

What we’ll do:

Santhosh Sudhaan
2 min readJun 12, 2021

Welcome to this blog, here in this blog we will write a program to ind circumference of circle with Python.

Formula:

To find the circumference of the circle, the formula is C = 2πr

calcworkshop.com

What’s happening:

First of all we declare function “getCirumference()” that takes given input as argument. Inside the function we initialize “PI” a constant variable as we know the value is not gonna change. So we define the “PI” variable to value 3.142.

Next we return 2xPIxr in which r is the input that we got from the user.

Finally we print the result, but here as I need only upto 2 decimal points so I am gonna say “.%2f”, so this prints only upto two digits after decimal point.

Source Code:

def getCircumference(r):
PI = 3.142 #Declaring the constant pi value
return 2*PI*r; #Performing 2xπxr
#function call
#Printing only 2 decimal digits so "%.2f"
#Test case 1
print("circumference is %.2f" %getCircumference(5));
#Test case 2
print("circumference is %.2f" %getCircumference(12));

Output:

circumference is 31.42
circumference is 75.40

What we learnt:

Through this blog, you learnt how to find the circumference of circle with Python.

Thank you.

--

--

No responses yet