Python Program to Calculate Circle Area
- Authors
- Name
- Emmanuel Hernandez
- @emmanuelhdev
14 min read
·# 3. Write a Python program which accepts the radius of a circle from the user and compute the area. (area = pi * r^2)
from math import pi
r = float(input("Enter the radius of the circle: "))
area = str(pi * r**2)
print("The area of the circle with radius " + str(r) + " is " + area)
Explanation:
- The program starts by importing the
pi
constant from themath
module. - It then prompts the user to enter the radius of the circle using the
input
function and converts the input to a float usingfloat()
. - The area of the circle is calculated using the formula
area = pi * r^2
, wherer
is the radius entered by the user. - The calculated area is converted to a string using
str()
and concatenated with a message string. - Finally, the message string containing the radius and calculated area is printed to the console.
Usage:
When you run this program, it will prompt you to enter the radius of the circle. For example:
Enter the radius of the circle: 5
After entering the radius, the program will output the calculated area:
The area of the circle with radius 5.0 is 78.53981633974483