How to calculate the area of a circle in Python
In this program, we will learn how to calculate the area of a circle in python by user input. that is, we will ask the user to enter the radius of the circle to perform the calculation.
But before that, we first learn how to calculate the area of the circle without taking an input from the user.
# this program is to calculate the area of a circle in python
# importing math function
import math
print("==================== AREA OF A CIRCLE CALCULATOR ====================")
radius = 3.5
# calculating the area
area = math.pi * radius * radius
# Displaying the answer to the user
print('THE AREA OF A CIRCLE IS:' + str(area))
![]() |
Calculating Area of a Circle in Python without User Input
Taking the radius of the circle as an input to calculate the area of a circle
# this program is to calculate the area of a circle in python
# importing math function
import math
print("======================== AREA OF A CIRCLE CALCULATOR ==========================")
# taking the radius of the circle from the user
radius = float(input('ENTER THE RADIUS OF THE CIRCLE: '))
# calculating the area
area = math.pi * radius * radius
# Displaying the answer to the user
print('THE AREA OF A CIRCLE IS:' + str(area))
![]() |
Calculating Area of a Circle in Python with User Input |
0 Comments