In the previous article, we have discussed Python Program for log() Function
acos() Function in Python:
The math.acos() method returns a number’s arc cosine value. Python acos, also known as Arc cosine, is the inverse of a cosine.
Note: It should be noted that the parameter passed to math.acos() must be between -1 and 1.
Tip: The value of PI will be returned by math.acos(-1).
Syntax:
math.acos(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 cosine.
- The acos() function returns the Arc Cosine value if the number argument is positive or negative.
- The acos() function returns TypeError if it is not a number.
- If it is not between -1 and 1, the acos() function returns ValueError.
Examples:
Example1:
Input:
Given first number = 0.5 Given second number = 1
Output:
The result after applying acos() function on above given first number 0.5 = 1.0471975511965979 The result after applying acos() function on above given second number 1 = 0.0
Example2:
Input:
Given first number = 0.3 Given second number = -0.2
Output:
The result after applying acos() function on above given first number 0.3 = 1.2661036727794992 The result after applying acos() function on above given second number -0.2 = 1.7721542475852274
Program for acos() 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.acos() function to the given first number to get the arc cosine value (inverse of cosine) of a given number.
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.acos() 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.5, 0.2, 1, 0.8] # Give the first number as static input and store it in another variable. gvn_numb1 = 0.5 # Apply math.acos() function to the given first number to get arc cosine value # (inverse of cosine) of a given number. # Store it in another variable. fnl_rslt = math.acos(gvn_numb1) print("The result after applying acos() 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 acos() function on above given second number", gvn_numb2, " = ", math.acos(gvn_numb2)) # Apply math.acos() function to the given list element and print it. print( "The result after applying acos() function on given list element gvnlst[1] = ", math.acos(gvn_lst[1]))
Output:
The result after applying acos() function on above given first number 0.5 = 1.0471975511965979 The result after applying acos() function on above given second number 1 = 0.0 The result after applying acos() function on given list element gvnlst[1] = 1.369438406004566
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.acos() function to the given first number to get the arc cosine value (inverse of cosine) of a given number.
- Store it in another variable.
- Print the above result.
- Similarly, do the same for the other number.
- Apply math.acos() 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.acos() function to the given first number to get arc cosine value # (inverse of cosine) of a given number. # Store it in another variable. fnl_rslt = math.acos(gvn_numb1) print("The result after applying acos() 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 acos() function on above given second number", gvn_numb2, " = ", math.acos(gvn_numb2)) # Apply math.acos() function to the given list element and print it. print( "The result after applying acos() function on given list element gvnlst[2] = ", math.acos(gvn_lst[2]))
Output:
Enter some random List Elements separated by spaces = 1 2 0.3 0.5 Enter some random number = 0.38 The result after applying acos() function on above given first number 0.38 = 1.181000030320636 Enter some random number = 0.6 The result after applying acos() function on above given second number 0.6 = 0.9272952180016123 The result after applying acos() function on given list element gvnlst[2] = 1.2661036727794992
Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.