Python Program for atan() Function

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

The arc tangent of a number (x) is returned as a numeric value between -PI/2 and PI/2 radians by the math.atan() method.

Arc tangent is also defined as an inverse tangent function of x, where x is the value to be calculated for the arc tangent.

Syntax:

math.atan(x)

Parameters:

x: This is Required. It is a number that is either positive or negative. If x is not a number, TypeError is returned.

Return Value:

It returns a float value ranging from -PI/2 to PI/2 representing a number’s arc tangent.

The Arc Tangent value is returned if the number argument is positive or negative.
The atan() function throws a TypeError if the number argument is not a number.

Examples:

Example1:

Input:

Given first number = 0.7
Given second number = 1

Output:

The result after applying atan() function on above given first number 0.7  =  0.6107259643892086
The result after applying atan() function on above given second number 1  =  0.7853981633974483

Example2:

Input:

Given first number = -1
Given second number = 0.3

Output:

The result after applying atan() function on above given first number -1  =  -0.7853981633974483
The result after applying atan() function on above given second number 0.3  =  0.2914567944778671

Program for atan() 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.atan() function to the given first number to get the arc tangent value (inverse of tangent ) of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.atan() 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.6, -0.3, 1, 0.8]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 0.7
# Apply math.atan() function to the given first number to get arc tangent value
# (inverse of tangent) of a given number.
# Store it in another variable.
fnl_rslt = math.atan(gvn_numb1)
print("The result after applying atan() 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 atan() function on above given second number",
      gvn_numb2, " = ", math.atan(gvn_numb2))
# Apply math.atan() function to the given list element and print it.
print(
    "The result after applying atan() function on given list element gvnlst[1] = ", math.atan(gvn_lst[1]))

Output:

The result after applying atan() function on above given first number 0.7  =  0.6107259643892086
The result after applying atan() function on above given second number 1  =  0.7853981633974483
The result after applying atan() function on given list element gvnlst[1] =  -0.2914567944778671

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.atan() function to the given first number to get the arc tangent value (inverse of tangent ) of a given number.
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.atan() 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.atan() function to the given first number to get arc tangent value
# (inverse of tangent) of a given number.
# Store it in another variable.
fnl_rslt = math.atan(gvn_numb1)
print("The result after applying atan() 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 atan() function on above given second number",
      gvn_numb2, " = ", math.atan(gvn_numb2))
# Apply math.atan() function to the given list element and print it.
print(
    "The result after applying atan() function on given list element gvnlst[2] = ", math.atan(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 0 2 0.9 1 -3
Enter some random number = -1
The result after applying atan() function on above given first number -1.0 = -0.7853981633974483
Enter some random number = 0.3
The result after applying atan() function on above given second number 0.3 = 0.2914567944778671
The result after applying atan() function on given list element gvnlst[2] = 0.7328151017865066

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