In the previous article, we have discussed Python Program for acos() Function
asin() Function in Python:
The arc sine of a number is returned by the math.asin() method.
Note: It should be noted that the parameter passed in math.asin() must be between -1 and 1.
Tip: math.asin(1) returns the value PI/2, while math.asin(-1) returns the value -PI/2. (where PI= 22/7)
Syntax:
math.asin(x)
Parameters:
x: This is required. It is a number between -1 and 1. If x is not a number, a TypeError is returned.
Return Value:
Returns a float value which represents a number’s arc sine.
- The asin() function returns the Arc Sine value if the number argument is positive or negative.
- The asin() function returns TypeError if it is not a number.
- If it is not between -1 and 1, the asin() function returns ValueError.
Examples:
Example1:
Input:
Given first number = 0.5 Given second number = 1
Output:
The result after applying asin() function on above given first number 0.5 = 0.5235987755982989 The result after applying asin() function on above given second number 1 = 1.5707963267948966
Example2:
Input:
Given first number = -1 Given second number = 0.6
Output:
The result after applying asin() function on above given first number -1 = -1.5707963267948966 The result after applying asin() function on above given second number 0.6 = 0.6435011087932844
Program for asin() 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 as static input and store it in another variable.
- Apply math.asin() function to the given first number to get the arc sine value (inverse of sine) of a given number.
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.asin() 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, 0.1, -0.4, 0.75]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 0.5
# Apply math.asin() function to the given first number to get arc sine value
# (inverse of sine) of a given number.
# Store it in another variable.
fnl_rslt = math.asin(gvn_numb1)
print("The result after applying asin() 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 asin() function on above given second number",
gvn_numb2, " = ", math.asin(gvn_numb2))
# Apply math.asin() function to the given list element and print it.
print(
"The result after applying asin() function on given list element gvnlst[1] = ", math.asin(gvn_lst[1]))
Output:
The result after applying asin() function on above given first number 0.5 = 0.5235987755982989 The result after applying asin() function on above given second number 1 = 1.5707963267948966 The result after applying asin() function on given list element gvnlst[1] = 0.1001674211615598
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 as user input using the float(input()) function and store it in a variable.
- Apply math.asin() function to the given first number to get the arc sine value (inverse of sine) of a given number.
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.asin() 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 as user input using the float(input()) function
# and store it in a variable.
gvn_numb1 = float(input("Enter some random number = "))
# Apply math.asin() function to the given first number to get arc sine value
# (inverse of sine) of a given number.
# Store it in another variable.
fnl_rslt = math.asin(gvn_numb1)
print("The result after applying asin() 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 asin() function on above given second number",
gvn_numb2, " = ", math.asin(gvn_numb2))
# Apply math.asin() function to the given list element and print it.
print(
"The result after applying asin() function on given list element gvnlst[2] = ", math.asin(gvn_lst[2]))
Output:
Enter some random List Elements separated by spaces = 0 3 -0.5 3 -1 Enter some random number = -1 The result after applying asin() function on above given first number -1.0 = -1.5707963267948966 Enter some random number = 0.6 The result after applying asin() function on above given second number 0.6 = 0.6435011087932844 The result after applying asin() function on given list element gvnlst[2] = -0.5235987755982989
Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.