Python BasicsEasy

Calculate the area of a circle

Detailed guide and Python implementation for the 'Calculate the area of a circle' problem.

Problem Statement

Easy

Write a function area_of_circle(radius) that takes a non-negative number radius and returns the area of a circle with that radius, rounded to 2 decimal places.

Use the formula: Area = π × radius². Use math.pi or 3.14159265358979 for π.

Constraints
  • 0 <= radius <= 10^4

Examples

Example 1
Input
area_of_circle(5)
Output
78.54
Explanation

Area = π × 5² = π × 25 = 78.5398... ≈ 78.54.

Example 2
Input
area_of_circle(1)
Output
3.14
Explanation

Area = π × 1² = π ≈ 3.14.

Example 3
Input
area_of_circle(7)
Output
153.94
Explanation

Area = π × 7² = π × 49 = 153.938... ≈ 153.94.

Need a Hint?
Consider using Numbers-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.