This Python script calculates and displays the circumference and area of a circle based on a user-provided radius.
import math
r = int(input("Please enter radius: "))
circumference = 2 * math.pi * r
area = math.pi * pow(r, 2)
print("Circumference: " + repr(round(circumference, 2)))
print("Circular Area: " + repr(round(area, 2)))
Please enter radius: 5
Circumference: 31.42
Circular Area: 78.54
math
Moduleimport math
math
module provides access to mathematical functions like pi
and pow
, which are essential for our calculations.r = int(input("Please enter radius: "))
input("Please enter radius: ")
: Prompts the user to enter the radius of the circle.int(...)
: Converts the input string to an integer.circumference = 2 * math.pi * r
math.pi
: Provides the value of π (Pi).r
.area = math.pi * pow(r, 2)
pow(r, 2)
: Computes 𝑟2r2, the square of the radius.math.pi
: Multiplies π by the square of the radius to get the area.print("Circumference: " + repr(round(circumference, 2)))
print("Circular Area: " + repr(round(area, 2)))
round(circumference, 2)
: Rounds the circumference to 2 decimal places.repr(...)
: Converts the rounded number to a string for printing.