Here,We are going to write python program to find diameter,circumference and area of circle using function . We can use some mathematical formulas to find diameter,circumference and area of circle. In this python program,We can create user defined function to calculate all this.

Write Python Program to find Diameter,Circumference and Area Of a Circle using function with a practical example.

The mathematical formulas are:

  1. Diameter of a Circle = 2r = 2 * radius
  2. Area of a circle is: A = πr² =  3.14 * radius * radius
  3. Circumference of a Circle = 2πr = 2 * 3.14 * radius

Problem Description:

The program takes value of radius of circle from user and calculate Circumference, Diameter, and Area of a Circle using user defined function

Program Logic:

  1. Take the values of radius of circle from the user using the float(input()) function and store it in  variable say r.
  2. Call function cal_Diameter and pass the value of radius  as an argument to the cal_Diameter function.
  3. Call function cal_Circum and pass the value of radius  as an argument to the cal_Circum function.
  4. Call function cal_Ares and pass the value of radius  as an argument to the cal_Area function.
  5. Create a  user defined functions to say cal_Diameter,which takes the value of radius as an argument using def keyword and return calculated result.
  6. Store result in variable say diameter.
  7. Create a  user defined functions to say cal_Circum, which takes the value of radius as an argument using def keyword and return calculated result.
  8. Store result in variable say circumference.
  9. Create a  user defined functions to say cal_Area  which takes the value of radius as an argument using def keyword and return calculated result.
  10. Store result in variable say area
  11. Print the variables diameter, circumference and area as output and exit.

Below is Implementation code/Source Code :

Here is source code of the Python Program to find Diameter Circumference and Area Of a Circle using function with a practical example.  The program output is also shown below.

import math
def cal_Diameter(radius):
    return 2 * radius
def cal_Circum(radius):
    return 2 * math.pi * radius
def cal_Area(radius):
    return math.pi * radius * radius
r = float(input("Enter the radius of a circle: "))
diameter = cal_Diameter(r)
circumference = cal_Circum(r)
area = cal_Area(r)
print("Diameter Of a Circle = %.2f" %diameter)
print("Circumference Of a Circle = %.2f" %circumference)
print("Area Of a Circle = %.2f" %area)


Output:

Enter the radius of a circle: 5

 Diameter Of a Circle = 10.00

 Circumference Of a Circle = 31.42

 Area Of a Circle = 78.54

<

Leave a Reply

Your email address will not be published.