Python Program to Find out the Arc Length of an Angle

In the previous article, we have discussed Python Program to Calculate Surface Area and Volume of a Cylinder
Arc Length :

The length of an arc is defined as the length of a circle’s circumference.

The arc length formula is as follows:

Arc length = (π*d) * (A/360)

where ‘d ‘ is the diameter of the circle.

‘A’ is the angle.

Given the diameter and angle of the circle, and the task is to find the arc length of the given angle.

Examples:

Example 1:

Input:

Given Diameter  = 10
Given Angle = 100

Output: 

The arc length of the given angle = 8.727

Example 2:

Input:

Given Diameter = 15
Given Angle =  450

Output: 

The above Entered Angle is Invalid

Program to Find out the Arc Length of an Angle

Below are the ways to find the arc length of the given angle.

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the diameter of the circle as static input and store it in a variable.
  • Give the angle as static input and store it in another variable.
  • Check if the given angle is greater than or equal to 360 using the if conditional statement.
  • If the statement is true, then print “The above-Entered Angle is Invalid”.
  • Else calculate the Arc length of the given angle using the above mathematical formula, math. pi () method and store it in another variable.
  • Print the arc length of the given angle.
  • The Exit of the program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the diameter of the circle as static input and store it in a variable.
gvn_diametr = 10
# Give the angle as static input and store it in another variable.
gvn_Angle = 100
# Check if the given angle is greater than or equal to 360 using if conditional statement.
if gvn_Angle >= 360:
  # If the statement is true, then print "The above Entered Angle is Invalid".
    print("The above Entered Angle is Invalid")
else:
    # Else Calculate the Arc length of the given angle using the above mathematical formula,
    # math.pi() method and store it in another variable.
    Arc_len = (math.pi*gvn_diametr) * (gvn_Angle/360)
# Print the arc length of the given angle.
    print("The arc length of the given angle = %.3f" % Arc_len)

Output: 

The arc length of the given angle = 8.727

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the diameter of the circle as user input using the float(input()) function and store it in a variable.
  • Give the angle as user input using the float(input()) function and store it in another variable.
  • Check if the given angle is greater than or equal to 360 using the if conditional statement.
  • If the statement is true, then print “The above-Entered Angle is Invalid”.
  • Else Calculate the Arc length of the given angle using the above mathematical formula, math.pi () method and store it in another variable.
  • Print the arc length of the given angle.
  • The Exit of the program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the diameter of the circle as user input using the float(input()) function and
# store it in a variable.
gvn_diametr = float(input("Enter some random number = "))
# Give the angle as user input using the float(input()) function and
# store it in another variable.
gvn_Angle = float(input("Enter some random number = "))
# Check if the given angle is greater than or equal to 360 using if conditional statement.
if gvn_Angle >= 360:
  # If the statement is true, then print "The above Entered Angle is Invalid".
    print("The above Entered Angle is Invalid")
else:
# Else Calculate the Arc length of the given angle using the above mathematical formula,
# math.pi() method and store it in another variable.
    Arc_len = (math.pi*gvn_diametr) * (gvn_Angle/360)
# Print the arc length of the given angle.
    print("The arc length of the given angle = %.3f" % Arc_len)

Output: 

Enter some random number = 15
Enter some random number = 90
The arc length of the given angle = 11.781

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.