Python Program for sin() Function

In the previous article, we have discussed Python Program for cos() Function
sin() Function in Python:

The sine of a number is returned by the math.sin() method.

The Sine function’s mathematical formula is:

sin(A) = length of opposite side/length of hypotenuse

Syntax:

math.sin(x)

Parameters:

x: This is Required. It is the number to calculate the sine of. If the value is not a number, a TypeError is returned.

Return value:

Returns a float value ranging from -1 to 1 that represents the sine of an angle.

Examples:

Example1:

Input:

Given first number (angle) = 15  
Given second number (angle) = 1

Output:

The result after applying sin() function on above given first number 15  =  0.6502878401571168
The result after applying sin() function on above given second number 1  =  0.8414709848078965

Example2:

Input:

Given first number (angle) = 10
Given second number (angle) = 4

Output:

The result after applying sin() function on above given first number 10  =  -0.5440211108893698
The result after applying sin() function on above given second number 4  =  -0.7568024953079282

Program for sin() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as static input and store it in a variable.
  • Give the first number(angle) as static input and store it in another variable.
  • Apply math.sin() function to the given first number to get the sine value of a given number (angle).
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.sin() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as static input and store it in a variable.
gvn_lst = [0.92, 2, -0.4, 0.75]
# Give the first number (angle) as static input and store it in another variable.
gvn_numb1 = 15
# Apply math.sin() function to the given first number to get the sine value
# of a given number (angle).
# Store it in another variable.
fnl_rslt = math.sin(gvn_numb1)
print("The result after applying sin() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 1
print("The result after applying sin() function on above given second number",
      gvn_numb2, " = ", math.sin(gvn_numb2))
# Apply math.sin() function to the given list element and print it.
print(
    "The result after applying sin() function on given list element gvnlst[1] = ", math.sin(gvn_lst[1]))

Output:

The result after applying sin() function on above given first number 15  =  0.6502878401571168
The result after applying sin() function on above given second number 1  =  0.8414709848078965
The result after applying sin() function on given list element gvnlst[1] =  0.9092974268256817

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in a variable.
  • Give the first number (angle) as user input using the float(input()) function and store it in a variable.
  • Apply math.sin() function to the given first number to get the sine value of a given number (angle).
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.sin() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_lst = list(map(float, input(
    'Enter some random List Elements separated by spaces = ').split()))
# Give the first number(angle) as user input using the float(input()) function
# and store it in a variable.
gvn_numb1 = float(input("Enter some random number = "))
# Apply math.sin() function to the given first number to get the sine value
# of a given number (angle).
# Store it in another variable.
fnl_rslt = math.sin(gvn_numb1)
print("The result after applying sin() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = float(input("Enter some random number = "))
print("The result after applying sin() function on above given second number",
      gvn_numb2, " = ", math.sin(gvn_numb2))
# Apply math.sin() function to the given list element and print it.
print(
    "The result after applying sin() function on given list element gvnlst[2] = ", math.sin(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 3 2 6 2 1
Enter some random number = 8
The result after applying sin() function on above given first number 8.0 = 0.9893582466233818
Enter some random number = -5
The result after applying sin() function on above given second number -5.0 = 0.9589242746631385
The result after applying sin() function on given list element gvnlst[2] = -0.27941549819892586

Note: To find the sine of degrees, first convert it to radians using math.radians() method.

For Example:

Approach:

  • Import math module using the import keyword.
  • Give the first number(angle) as static input and store it in another variable.
  • Get the angle in degree by first converting the given angle into radians using math. radians() method and then apply math.sin() method to it.
  • Print the given angle in degrees.
  • Similarly, do the same for another angle.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the first number(angle) as static input and store it in another variable.
gvn_numb1 = 45
# Get the angle in degree by first converting the given angle into radians using
# the math. radians() method and then apply math.sin() method to it.
angl_in_degre = math.sin(math.radians(gvn_numb1))
# Print the given angle in degrees.
print("The sin value of the given angle",
      gvn_numb1, " in degrees = ", angl_in_degre)
# similarly do the same for other angle
gvn_numb2 = 60
angl_in_degre = math.sin(math.radians(gvn_numb2))
print("The sin value of the given angle",
      gvn_numb2, " in degrees = ", angl_in_degre)

Output:

The sin value of the given angle 45  in degrees =  0.7071067811865475
The sin value of the given angle 60  in degrees =  0.8660254037844386

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.