{"id":24347,"date":"2021-10-14T09:46:28","date_gmt":"2021-10-14T04:16:28","guid":{"rendered":"https:\/\/python-programs.com\/?p=24347"},"modified":"2021-11-05T21:06:25","modified_gmt":"2021-11-05T15:36:25","slug":"python-program-for-tan-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-tan-function\/","title":{"rendered":"Python Program for tan() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for sin() Function<\/a> The tangent of a number is returned by the math.tan() method.<\/p>\n The tangent function’s mathematical formula is:<\/p>\n tan(A) = length of opposite side\/length of adjacent side<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong><\/p>\n x:<\/strong> This is Required. It is the number to calculate the tangent of. If the value is not a number, a TypeError is returned.<\/p>\n Return Value: <\/strong><\/p>\n Returns a float value representing a number’s tangent.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/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 Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples<\/a> well explained step by step.<\/p>\n In the previous article, we have discussed Python Program for sin() Function tan() Function in Python: The tangent of a number is returned by the math.tan() method. The tangent function’s mathematical formula is: tan(A) = length of opposite side\/length of adjacent side Syntax: math.tan(x) Parameters: x: This is Required. It is the number to calculate …<\/p>\n
\ntan() Function in Python:<\/strong><\/p>\nmath.tan(x)<\/pre>\n
\n
Given first number (angle) = 60\r\nGiven second number (angle) = 45<\/pre>\n
The result after applying tan() function on above given first number 60 = 0.320040389379563\r\nThe result after applying tan() function on above given second number 45 = 1.6197751905438615<\/pre>\n
Given first number (angle) = 90\r\nGiven second number (angle) = 15<\/pre>\n
The result after applying tan() function on above given first number 90 = -1.995200412208242\r\nThe result after applying tan() function on above given second number 15 = -0.8559934009085187<\/pre>\n
Program for tan() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as static input and store it in a variable.\r\ngvn_lst = [5, 15, 6, 7]\r\n# Give the first number (angle) as static input and store it in another variable.\r\ngvn_numb1 = 60\r\n# Apply math.tan() function to the given first number to get the tangent value\r\n# of a given number (angle).\r\n# Store it in another variable.\r\nfnl_rslt = math.tan(gvn_numb1)\r\nprint(\"The result after applying tan() function on above given first number\",\r\n gvn_numb1, \" = \", fnl_rslt)\r\n# similarly do the same for the other number.\r\ngvn_numb2 = 45\r\nprint(\"The result after applying tan() function on above given second number\",\r\n gvn_numb2, \" = \", math.tan(gvn_numb2))\r\n# Apply math.tan() function to the given list element and print it.\r\nprint(\r\n \"The result after applying tan() function on given list element gvnlst[1] = \", math.tan(gvn_lst[1]))\r\n<\/pre>\n
The result after applying tan() function on above given first number 60 = 0.320040389379563\r\nThe result after applying tan() function on above given second number 45 = 1.6197751905438615\r\nThe result after applying tan() function on given list element gvnlst[1] = -0.8559934009085187<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_lst = list(map(float, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Give the first number(angle) as user input using the float(input()) function\r\n# and store it in a variable.\r\ngvn_numb1 = float(input(\"Enter some random number = \"))\r\n# Apply math.tan() function to the given first number to get the tangent value\r\n# of a given number (angle).\r\n# Store it in another variable.\r\nfnl_rslt = math.tan(gvn_numb1)\r\nprint(\"The result after applying tan() function on above given first number\",\r\n gvn_numb1, \" = \", fnl_rslt)\r\n# similarly do the same for the other number.\r\ngvn_numb2 = float(input(\"Enter some random number = \"))\r\nprint(\"The result after applying tan() function on above given second number\",\r\n gvn_numb2, \" = \", math.tan(gvn_numb2))\r\n# Apply math.tan() function to the given list element and print it.\r\nprint(\r\n \"The result after applying tan() function on given list element gvnlst[2] = \", math.tan(gvn_lst[2]))\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 10 20 30 40 50\r\nEnter some random number = 90\r\nThe result after applying tan() function on above given first number 90.0 = -1.995200412208242\r\nEnter some random number = 65\r\nThe result after applying tan() function on above given second number 65.0 = -1.4700382576631723\r\nThe result after applying tan() function on given list element gvnlst[2] = -6.405331196646276<\/pre>\n
\n