Python Program for Area of Circle. Creating a Python program to calculate the area of a circle is a perfect way to get started with Python. It involves baisc concepts such as mathematicals operations and input/output functions. Let’s see how we can write Python program for area of circle step by step-
Table of Contents
Area of Circle Formula
The area of circle is calculated using the formula-
Area = πxr2
Here π is a constant approximately equal to 3.14159 and r is the radius of circle.
Get User Input for the Radius
First you need to prompt the user to enter the radius of circle. Python provides a built-in function input()
for this purpose. Since input()
returns a string, you will need to convert this string to a float or integer using float()
or int()
for mathematical operations.
radius = float(input("Enter the radius of circle "))
Calculate the Area
Now that you have the radius, you can calculate the area of circle using the formula mentioned above. Python uses '*'
for multiplication and '**'
for exponentiation.
area = 3.14159*radius**2
Display the Result
Finally, display the calculate area to the user. You can do this using the print() function.
print("The area of circle is = ",area)
Complete Python Program for Area of Circle
Putting it all together, Here is the complete Python program for area of Circle.
radius = float(input("Enter the radius of circle "))
area = 3.14159*radius**2
print("The area of circle is = ",area)
Congratulations!! you have just written a simple Pyton program to calculate the area of circle. This tutorial not only taught you how to calculate the area of circle using Python code but also introduced you to basic concepts in Python programing such as variable, user input, mathematical operations, and printing the output.
Happy Coding & Learning
1 thought on “Python Program for Area of Circle”