Calculate the area of a circle
Detailed guide and Python implementation for the 'Calculate the area of a circle' problem.
Problem Statement
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 π.
- •0 <= radius <= 10^4
Examples
area_of_circle(5)
78.54
Area = π × 5² = π × 25 = 78.5398... ≈ 78.54.
area_of_circle(1)
3.14
Area = π × 1² = π ≈ 3.14.
area_of_circle(7)
153.94
Area = π × 7² = π × 49 = 153.938... ≈ 153.94.
Need a Hint?
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.
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Variables & Data Types Explained
Understand Python variables and core data types (strings, integers, floats, booleans). A complete beginner guide to memory assignment in Python.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python Dictionary Methods
Learn Python dictionary methods. Complete reference guide for key-value pair insertions, retrievals, updates, and checks.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.