Python program to enter the radius of a circle and find its diameter, circumference, and area. There are you will learn how to find the diameter, circumference, and area of a circle in Python language.
Formula:
D = 2 * r
C = 2 * PI * r
A = PI * r2
where:
r
= radius of the circle
D
= diameter of the circle
C
= circumference of the circle
A
= area of the circle
There are two ways to implement these formulae:
- By using the default value of PI = 3.14
- Second, by using math.pi constant
1. By using the default value of PI = 3.14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# Python program to find diameter, circumference, and area of a circle print("Enter the radius of the circle::\n") r, d, c, a = float(input()), None, None, None # r = radius # d = diameter # c = circumference # a = area # Calculation of diameter, circumference and area d = 2 * r c = 2 * 3.14 * r a = 3.14 * (r * r) print("Diameter = ", d, "units") print("Circumference = ", c, "units") print("Area = ", a, " sq. units") |
Output:
1 2 3 4 5 6 7 8 9 |
Enter the radius of the circle:: 7 Diameter = 14.0 units Circumference = 43.96 units Area = 153.86 sq. units |
2. By using math.pi constant
Note: before using math.pi constant you have to import math library in the program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Python program to find diameter, circumference, and area of a circle # Import math Library import math print("Enter the radius of the circle::\n") r, d, c, a = float(input()), None, None, None # r = radius # d = diameter # c = circumference # a = area # Calculation of diameter, circumference and area d = 2 * r c = 2 * math.pi * r a = math.pi * (r * r) print("Diameter = ", d, "units") print("Circumference = ", c, "units") print("Area = ", a, " sq. units") |
Output:
1 2 3 4 5 6 7 8 9 |
Enter the radius of the circle:: 7 Diameter = 14.0 units Circumference = 43.982297150257104 units Area = 153.93804002589985 sq. units |