Back to Practice Dashboard
Python BasicsEasy
Calculate the area of a circle
Learn how to solve the 'Calculate the area of a circle' problem. This detailed resource details brute force and optimized approaches.
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?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.