{"id":24341,"date":"2021-10-14T09:46:23","date_gmt":"2021-10-14T04:16:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=24341"},"modified":"2021-11-05T21:07:10","modified_gmt":"2021-11-05T15:37:10","slug":"python-program-for-hypot-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-hypot-function\/","title":{"rendered":"Python Program for hypot() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for atanh() Function<\/a> The square root of the sum of squares of the specified arguments is returned by the Python hypot() function.<\/p>\n The Euclidean norm is returned by the math.hypot() method. The Euclidian norm is the distance between the origin and the given coordinates.<\/p>\n This method was only used prior to Python 3.8 to find the hypotenuse of a right-angled triangle: sqrt(x*x + y*y).<\/p>\n Since Python 3.8, this method is also used to compute the Euclidean norm. The coordinates passed are assumed to be like in n-dimensional cases (x1, x2, x3, …, xn). So sqrt(x1*x1 + x2*x2 + x3*x3…. xn*xn) is used to calculate Euclidean length from the origin.<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong><\/p>\n x1, x2, x3,. . . . ,xn:<\/strong> These are required. These are numbers. Two or more coordinates are represented by two or more points.<\/p>\n Return Value:<\/strong><\/p>\n For n inputs, the return value is a float representing the Euclidean distance from the origin, or the hypotenuse of a right-angled triangle for two inputs.<\/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 atanh() Function hypot() Function in Python: The square root of the sum of squares of the specified arguments is returned by the Python hypot() function. The Euclidean norm is returned by the math.hypot() method. The Euclidian norm is the distance between the origin and the …<\/p>\n
\nhypot() Function in Python:<\/strong><\/p>\nmath.hypot(x1, x2, x3,. . . .xn )<\/pre>\n
\n
Given first number = 2\r\nGiven second number = 3<\/pre>\n
The result after applying hypot() function on above given first and second { 2 , 3 } numbers = 3.605551275463989<\/pre>\n
Given first number = 4\u00a0\u00a0\r\nGiven second number = 3<\/pre>\n
The result after applying hypot() function on above given first and second { 4 , 3 } numbers = 5.0<\/pre>\n
Program for hypot() 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 = [1, 2, 4, 0]\r\n# Give the first number as static input and store it in another variable.\r\ngvn_numb1 = 2\r\n# Give the second number as static input and store it in another variable.\r\ngvn_numb2 = 3\r\n# Apply math.hypot() function on the given first and the second numbers to get\r\n# the square root of the sum of squares of the specified arguments.i.e\r\n# (given first and second numbers )\r\n# Store it in another variable.\r\nfnl_rslt = math.hypot(gvn_numb1, gvn_numb2)\r\n# Print the above result which is the result after applying math.hypot() function.\r\nprint(\"The result after applying hypot() function on above given first and second {\",\r\n gvn_numb1, \",\", gvn_numb2, \"} numbers = \", fnl_rslt)\r\n# Give the number as static input and store it in another variable.\r\ngvn_numb3 = 5\r\n# Apply math.hypot() function to the given list element and above given number\r\n# and print it.\r\nprint(\"The result after applying hypot() function on the given list element gvn_lst[1] and above given number = \", math.hypot(\r\n gvn_lst[1], gvn_numb3))\r\n<\/pre>\n
The result after applying hypot() function on above given first and second { 2 , 3 } numbers = 3.605551275463989\r\nThe result after applying hypot() function on the given list element gvn_lst[1] and above given number = 5.385164807134504<\/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(int, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Give first and second numbers respectively as user input using \r\n# int(), map(), input(), and split() functions.\r\ngvn_numb1, gvn_numb2 = map(int, input(\r\n \"Enter two random numbers separated by spaces = \").split())\r\n# Apply math.hypot() function on the given first and the second numbers to get\r\n# the square root of the sum of squares of the specified arguments.i.e\r\n# (given first and second numbers )\r\n# Store it in another variable.\r\nfnl_rslt = math.hypot(gvn_numb1, gvn_numb2)\r\n# Print the above result which is the result after applying math.hypot() function.\r\nprint(\"The result after applying hypot() function on above given first and second {\",\r\n gvn_numb1, \",\", gvn_numb2, \"} numbers = \", fnl_rslt)\r\n# Give the number as user input using the int(input()) function and store it in another variable.\r\ngvn_numb3 = int(input(\"Enter some random number = \"))\r\n# Apply math.hypot() function to the given list element and above given number\r\n# and print it.\r\nprint(\"The result after applying hypot() function on the given list element gvn_lst[2] and above given number = \", math.hypot(\r\n gvn_lst[2], gvn_numb3))\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 2 3 4 1 \r\nEnter two random numbers separated by spaces = 4 6\r\nThe result after applying hypot() function on above given first and second { 4 , 6 } numbers = 7.211102550927978\r\nEnter some random number = 3\r\nThe result after applying hypot() function on the given list element gvn_lst[2] and above given number = 5.0<\/pre>\n
\n