Program to Find the Sine Series for the Given range

Python Program to Find the Sine Series for the Given range

In the previous article, we have discussed Python Program to Find Super Factorial of a Number.
Math Module :

Python’s math module is a built-in module. By importing this module, we can perform mathematical computations.

Numerous mathematical operations like ceil( ),floor( ),factorial( ),mod( ),value of pi ,…..etc .can be computed with the help of math module.

math.sin() function:

To compute the sine value, we must use the sine function as math. sine() takes only one parameter, the degree value.

Sin is a trigonometric function that represents the Sine function. Its value can be calculated by dividing the length of the opposite side by the length of the hypotenuse of a right-angled triangle, as we learned in math.

By importing the math module that contains the definition, we will be able to use the sin() function in Python to obtain the sine value for any given angle.

Examples:

Example1:

Input:

Given lower limit range =0
Given upper limit range =181
Given step size =30

Output:

The Sine values in a given range are : 
sin 0 = 0.0
sin 30 = 0.49999999999999994
sin 60 = 0.8660254037844386
sin 90 = 1.0
sin 120 = 0.8660254037844387
sin 150 = 0.49999999999999994
sin 180 = 1.2246467991473532e-16

Example 2:

Input:

Given lower limit range =  50
Given upper limit range = 200 
Given step size = 20

Output:

The Sine values in a given range are : 
sin 50 = 0.766044443118978
sin 70 = 0.9396926207859083
sin 90 = 1.0
sin 110 = 0.9396926207859084
sin 130 = 0.766044443118978
sin 150 = 0.49999999999999994
sin 170 = 0.17364817766693028
sin 190 = -0.17364817766693047

Program to Find the Sine Series for the Given range

Below are the ways to find the sine values in the Given Range.

Method #1: Using math Module (Static input)

Approach:

  • Import math module using the import keyword.
  • Give the lower limit range as static input and store it in a variable.
  • Give the upper limit range as static input and store it in another variable.
  • Give the step size as static input and store it in another variable.
  • Loop from lower limit range to upper limit range using For loop.
  • Get the angle value in radians from the given range(converting from degree to radians ) and store it in a variable.
  • Calculate the Sine value in a given range for the above-obtained radian values using math.sin() function and store it in another variable.
  • Print the Sine Values in the above-given range.
  • The Exit of the program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the lower limit range as static input and store it in a variable.
lwer_lmt = 0
# Give the upper limit range as static input and store it in another variable.
upp_lmt = 181
# Give the step size as static input and store it in another variable.
stp_sze = 30
# Loop from lower limit range to upper limit range using For loop.
print("The Sine values in a given range are : ")
for vale in range(lwer_lmt, upp_lmt, stp_sze):
  # Get the angle value in radians from the given range(converting from degree to radians )
  # and store it in a variable.
    radns = math.radians(vale)
    # Calculate the Sine value in a given range of above obtained radian values using
    # math.Sine()function and store it in another variable.
    sine_vlue = math.sin(radns)
    # print the Sine Values in the above given range.
    print("sin",vale, "=", sine_vlue)

Output:

The Sine values in a given range are : 
sin 0 = 0.0
sin 30 = 0.49999999999999994
sin 60 = 0.8660254037844386
sin 90 = 1.0
sin 120 = 0.8660254037844387
sin 150 = 0.49999999999999994
sin 180 = 1.2246467991473532e-16

Method #2: Using math Module (User input)

Approach:

  • Import math module using the import keyword.
  • Give the lower limit range as User input using the int(input()) function and store it in a variable.
  • Give the upper limit range as User input using the int(input()) function and store it in another variable.
  • Give the step size as User input and store it in another variable.
  • Loop from lower limit range to upper limit range using For loop.
  • Get the angle value in radians from the given range(converting from degree to radians ) and store it in a variable.
  • Calculate the Sine value in a given range for the above-obtained radian values using math.sin() function and store it in another variable.
  • print the Sine Values in the above-given range.
  • The Exit of the program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the lower limit range as User input using the int(input()) function and store it in a variable.
lwer_lmt = int(input('Enter some Random number ='))
# Give the upper limit range as User input using the int(input()) function and store it in another variable.
upp_lmt = int(input('Enter some Random number ='))
# Give the step size as User input and store it in another variable.
stp_sze = int(input('Enter some Random number ='))
# Loop from lower limit range to upper limit range using For loop.
print("The Sine values in a given range are : ")
for vale in range(lwer_lmt, upp_lmt, stp_sze):
  # Get the angle value in radians from the given range(converting from degree to radians )
  # and store it in a variable.
    radns = math.radians(vale)
    # Calculate the Sine value in a given range for the  above obtained radian values using
    # math.sin()function and store it in another variable.
    sine_vlue = math.sin(radns)
    # print the Sine Values in the above given range.
    print("sin",vale, "=", sine_vlue)

Output:

Enter some Random number = 50
Enter some Random number = 200
Enter some Random number = 20
The Sine values in a given range are : 
sin 50 = 0.766044443118978
sin 70 = 0.9396926207859083
sin 90 = 1.0
sin 110 = 0.9396926207859084
sin 130 = 0.766044443118978
sin 150 = 0.49999999999999994
sin 170 = 0.17364817766693028
sin 190 = -0.17364817766693047

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.