Tutorialspoint
Problem
Solution
Submissions

Calculate the Area of a Circle

Certification: Basic Level Accuracy: 60.57% Submissions: 279 Points: 5

Write a Python program that calculates the area of a circle given its radius.

Example 1
  • Input: 5
  • Output: 78.53981633974483
  • Explanation:
    • Step 1: Apply the formula for circle area: A = π × r².
    • Step 2: A = 3.141592653589793 × 5² = 3.141592653589793 × 25 = 78.53981633974483.
    • Step 3: Return 78.53981633974483 as the result.
Example 2
  • Input: 2.5
  • Output: 19.634954084936208
  • Explanation:
    • Step 1: Apply the formula for circle area: A = π × r².
    • Step 2: A = 3.141592653589793 × 2.5² = 3.141592653589793 × 6.25 = 19.634954084936208.
    • Step 3: Return 19.634954084936208 as the result.
Constraints
  • 0 < radius ≤ 10^6
  • Use π = 3.141592653589793 for calculations
  • Time Complexity: O(1)
  • Space Complexity: O(1)
NumberVariables and Data TypesPwCKPMG
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

 
  • Use the formula: area = π * r^2
  • Import math module: import math; area = math.pi * radius ** 2
  • Define π as a constant: PI = 3.141592653589793; area = PI * radius * radius
  • Use lambda function: area_calc = lambda r: math.pi * r * r

The following are the steps to calculate the Area of a Circle:

 1. Import the `math` module for accurate pi value.

 2. Define a function `area_of_circle(radius)`.
 3. Compute the area using `pie * radius^2`.
 4. Return the computed area.
 5. Call the function with radius `7` and store the result.
 6. Print the area.

Submitted Code :