{"id":16138,"date":"2021-08-12T09:36:44","date_gmt":"2021-08-12T04:06:44","guid":{"rendered":"https:\/\/python-programs.com\/?p=16138"},"modified":"2021-11-22T18:38:27","modified_gmt":"2021-11-22T13:08:27","slug":"python-program-to-get-tangent-value-using-math-tan","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-get-tangent-value-using-math-tan\/","title":{"rendered":"Python Program to Get Tangent value Using math.tan()"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Reverse each Word in a Sentence<\/a> Python’s math module is a built-in module. By importing this module, we can perform mathematical computations.<\/p>\n Numerous mathematical operations like ceil( ),floor( ),factorial( ),mod( ),value of pi ,…..etc .can be computed with the help of math module.<\/p>\n math.tan() Function in Python:<\/strong><\/p>\n Using this function, we can quickly find the tangent value for a given angle.<\/p>\n Tan is a trigonometric function that represents the Tangent function. 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.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to Get Tangent value.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" 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 …<\/p>\n
\nMath Module :<\/strong><\/p>\n
\nIts 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.<\/p>\nGiven lower limit range =0\r\nGiven upper limit range =181\r\nGiven step size =30<\/pre>\n
The Tangent values in a given range are tan( 0 ) = 0.0\r\nThe Tangent values in a given range are tan( 30 ) = 0.5773502691896257\r\nThe Tangent values in a given range are tan( 60 ) = 1.7320508075688767\r\nThe Tangent values in a given range are tan( 90 ) = 1.633123935319537e+16\r\nThe Tangent values in a given range are tan( 120 ) = -1.7320508075688783\r\nThe Tangent values in a given range are tan( 150 ) = -0.5773502691896257\r\nThe Tangent values in a given range are tan( 180 ) = -1.2246467991473532e-16<\/pre>\n
Given lower limit range = 40\r\nGiven upper limit range = 300\r\nGiven step size = 45<\/pre>\n
The Tangent values in a given range are tan( 40 ) = 0.8390996311772799\r\nThe Tangent values in a given range are tan( 85 ) = 11.430052302761348\r\nThe Tangent values in a given range are tan( 130 ) = -1.19175359259421\r\nThe Tangent values in a given range are tan( 175 ) = -0.08748866352592402\r\nThe Tangent values in a given range are tan( 220 ) = 0.8390996311772799\r\nThe Tangent values in a given range are tan( 265 ) = 11.430052302761332<\/pre>\n
Program to Get Tangent value using math.tan()<\/h2>\n
\n
Method #1: Using math Module (Static input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the lower limit range as static input and store it in a variable.\r\nlwer_lmt = 0\r\n# Give the upper limit range as static input and store it in another variable.\r\nupp_lmt = 181\r\n# Give the step size as static input and store it in another variable.\r\nstp_sze = 30\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor vale in range(lwer_lmt, upp_lmt, stp_sze):\r\n # Get the angle value in radians from the given range(converting from degree to radians )\r\n # and store it in a variable.\r\n radns = math.radians(vale)\r\n # Calculate the Tangent value in a given range of above obtained radian values using\r\n # tan()function and store it in another variable.\r\n tangt = math.tan(radns)\r\n # print the Tangent Values in the above given range.\r\n print(\"The Tangent values in a given range are tan(\", vale, ') = ', tangt)\r\n<\/pre>\n
The Tangent values in a given range are tan( 0 ) = 0.0\r\nThe Tangent values in a given range are tan( 30 ) = 0.5773502691896257\r\nThe Tangent values in a given range are tan( 60 ) = 1.7320508075688767\r\nThe Tangent values in a given range are tan( 90 ) = 1.633123935319537e+16\r\nThe Tangent values in a given range are tan( 120 ) = -1.7320508075688783\r\nThe Tangent values in a given range are tan( 150 ) = -0.5773502691896257\r\nThe Tangent values in a given range are tan( 180 ) = -1.2246467991473532e-16<\/pre>\n
Method #2: Using math Module (User input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the lower limit range as User input using the int(input(()) function and store it in a variable.\r\nlwer_lmt = int(input('Enter some Random number ='))\r\n# Give the upper limit range as User input using\u00a0the\u00a0int(input(())\u00a0function and store it in another variable.\r\nupp_lmt = int(input('Enter some Random number ='))\r\n# Give the step size as User input and store it in another variable.\r\nstp_sze = int(input('Enter some Random number ='))\r\n# Loop from lower limit range to upper limit range using For loop.\r\nfor vale in range(lwer_lmt, upp_lmt, stp_sze):\r\n # Get the angle value in radians from the given range(converting from degree to radians )\r\n # and store it in a variable.\r\n radns = math.radians(vale)\r\n # Calculate the Tangent value in a given range of above obtained radian values using\r\n # tan()function and store it in another variable.\r\n tangt = math.tan(radns)\r\n # print the Tangent Values in the above given range.\r\n print(\"The Tangent values in a given range are tan(\", vale, ') = ', tangt)\r\n<\/pre>\n
Enter some Random number = 40\r\nEnter some Random number = 300\r\nEnter some Random number = 45\r\nThe Tangent values in a given range are tan( 40 ) = 0.8390996311772799\r\nThe Tangent values in a given range are tan( 85 ) = 11.430052302761348\r\nThe Tangent values in a given range are tan( 130 ) = -1.19175359259421\r\nThe Tangent values in a given range are tan( 175 ) = -0.08748866352592402\r\nThe Tangent values in a given range are tan( 220 ) = 0.8390996311772799\r\nThe Tangent values in a given range are tan( 265 ) = 11.430052302761332<\/pre>\n
\n