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 |
|---|
| Python Variables |
| Python Data Types |
| Python Type Casting |
| Python Operators |
| Exercises & Assignments |
|---|
| Python program to add two numbers |
| Python program to swap two variables |
| Python program to find the area of a circle |
| Python program to convert Celsius to Fahrenheit |
| Interview Questions & Answers |
|---|
| What is the difference between == and is in Python? |