In this Tutorial -:

Understanding the Problem
The area of a circle is a fundamental geometric concept that measures the region enclosed by the circle’s circumference. The formula to calculate the area of a circle is:
Area = π * (radius)^2
In this tutorial, we’ll develop a Python program to find the area of a circle by taking the radius as input from the user.
Developing the Algorithm
-> Take user input for the radius of the circle.
-> Calculate the area of the circle using the provided formula.
-> Display the calculated area to the user.
Writing the Python Code
import math
# Function to calculate the area of a circle
def calculate_circle_area(radius):
area = math.pi * (radius ** 2)
return area
# Main function
def main():
# Input radius of the circle
radius = float(input("Enter the radius of the circle: "))
# Calculate the area of the circle
area = calculate_circle_area(radius)
# Display the result upto two decimal places
print("Area of the circle:", round(area, 2))
if __name__ == "__main__":
main()
O/P
Enter the radius of the circle: 5
Area of the circle: 78.54
Time Complexity
The time complexity of this program is constant (O(1)) because the execution time is not dependent on the value of the radius. The program will always execute the same number of operations regardless of the radius entered by the user.
Code Explanation
We start by importing the math module to access the value of π (pi) for accurate area calculation.
The calculate_circle_area function takes the radius as an argument and calculates the area of the circle using the provided formula. It returns the result.
The main function is defined to take user input for the radius of the circle.
User input is converted to a floating-point number using float(input(…)).
The calculate_circle_area function is called with the user-provided radius, and the result is stored in the area variable.
Finally, the calculated area of the circle is displayed to the user.
Dry Run
Let’s perform a dry run of the program with the following input:
Radius = 5.0
Execution:
-> User enters the radius of the circle: 5.0
-> The calculate_circle_area function is called with radius = 5.0.
-> The area of the circle is calculated as follows: area = π * (5.0 ** 2) ≈ 78.54
The calculated area of the circle (approximately 78.54) is displayed to the user as “Area of the circle: 78.54”.
The program successfully calculates and displays the area of the circle based on the user input.
