Python tan function: In the previous article, we have discussed Python Program to Reverse each Word in a Sentence
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.tan() Function in Python:
Using this function, we can quickly find the tangent value for a given angle.
Tan is a trigonometric function that represents the Tangent function.
Its value can be calculated by dividing the length of the opposite side by the length of the adjacent side 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 tan() function in Python to obtain the tangent value for any given angle.
- Python Program to Compute the Area and Perimeter of Octagon
- Python Program to Compute the Area and Perimeter of Heptagon
- Python Program to Find Isosceles Triangle Area
Examples:
Example1:
Input:
Given lower limit range =0 Given upper limit range =181 Given step size =30
Output:
The Tangent values in a given range are tan( 0 ) = 0.0 The Tangent values in a given range are tan( 30 ) = 0.5773502691896257 The Tangent values in a given range are tan( 60 ) = 1.7320508075688767 The Tangent values in a given range are tan( 90 ) = 1.633123935319537e+16 The Tangent values in a given range are tan( 120 ) = -1.7320508075688783 The Tangent values in a given range are tan( 150 ) = -0.5773502691896257 The Tangent values in a given range are tan( 180 ) = -1.2246467991473532e-16
Example 2:
Input:
Given lower limit range = 40 Given upper limit range = 300 Given step size = 45
Output:
The Tangent values in a given range are tan( 40 ) = 0.8390996311772799 The Tangent values in a given range are tan( 85 ) = 11.430052302761348 The Tangent values in a given range are tan( 130 ) = -1.19175359259421 The Tangent values in a given range are tan( 175 ) = -0.08748866352592402 The Tangent values in a given range are tan( 220 ) = 0.8390996311772799 The Tangent values in a given range are tan( 265 ) = 11.430052302761332
Program to Get Tangent value using math.tan()
Below are the ways to Get Tangent value.
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 Tangent value in a given range for the above-obtained radian values using math.tan() function and store it in another variable.
- print the Tangent 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. 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 Tangent value in a given range of above obtained radian values using # tan()function and store it in another variable. tangt = math.tan(radns) # print the Tangent Values in the above given range. print("The Tangent values in a given range are tan(", vale, ') = ', tangt)
Output:
The Tangent values in a given range are tan( 0 ) = 0.0 The Tangent values in a given range are tan( 30 ) = 0.5773502691896257 The Tangent values in a given range are tan( 60 ) = 1.7320508075688767 The Tangent values in a given range are tan( 90 ) = 1.633123935319537e+16 The Tangent values in a given range are tan( 120 ) = -1.7320508075688783 The Tangent values in a given range are tan( 150 ) = -0.5773502691896257 The Tangent values in a given range are tan( 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 Tangent value in a given range of the above-obtained radian values using the tan()function and store it in another variable.
- print the Tangent 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. 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 Tangent value in a given range of above obtained radian values using # tan()function and store it in another variable. tangt = math.tan(radns) # print the Tangent Values in the above given range. print("The Tangent values in a given range are tan(", vale, ') = ', tangt)
Output:
Enter some Random number = 40 Enter some Random number = 300 Enter some Random number = 45 The Tangent values in a given range are tan( 40 ) = 0.8390996311772799 The Tangent values in a given range are tan( 85 ) = 11.430052302761348 The Tangent values in a given range are tan( 130 ) = -1.19175359259421 The Tangent values in a given range are tan( 175 ) = -0.08748866352592402 The Tangent values in a given range are tan( 220 ) = 0.8390996311772799 The Tangent values in a given range are tan( 265 ) = 11.430052302761332
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.
- Python Program to Count Divisors of Factorial
- Python Program to Check if two Lines are Parallel or Not
- Python Program to Find Sum of Arithmetic Progression Series
- Python Program to Find Volume and Surface Area of a Cube