Python program to find the area of a circle
Description: Write a Python program to calculate the area of a circle when the radius is 5.
Rules and hints:
- Formula: area = pi x radius x radius.
- Use
math.pifor the value of pi. - Round the answer to 2 decimal places with
round().
Python program for the area of a circle
import math
radius = 5
area = math.pi * radius ** 2
print("Area of the circle:", round(area, 2))
Output:
Tutorials Class - Output Window
Area of the circle: 78.54
How it works
radius ** 2means radius to the power 2.math.piis 3.141592653589793, so the exact area is 78.53981633974483.round(area, 2)keeps two digits after the decimal point.
See also Python Modules to learn about import.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |