{"id":23811,"date":"2021-10-03T20:31:32","date_gmt":"2021-10-03T15:01:32","guid":{"rendered":"https:\/\/python-programs.com\/?p=23811"},"modified":"2021-11-22T18:33:25","modified_gmt":"2021-11-22T13:03:25","slug":"python-program-for-pythagorean-quadruple","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-pythagorean-quadruple\/","title":{"rendered":"Python Program for Pythagorean Quadruple"},"content":{"rendered":"
Given four points, the task is to check if the given four points form quadruple in python.<\/p>\n
Quadruple:<\/strong><\/p>\n It is defined as a tuple of integers a, b, c, and d such that a2<\/sup> + b2<\/sup>\u00a0 + c2<\/sup>\u00a0= d2<\/sup>. They are, in fact, Diophantine Equations solutions. It represents a cuboid with integer side lengths |a|, |b|, and |c| and a space diagonal of |d| in the geometric interpretation.<\/p>\n Condition to check Quadruple = a2<\/sup> + b2<\/sup>\u00a0 + c2<\/sup>\u00a0= d2<\/sup><\/strong><\/p>\n where a, b, c, d are the given four points.<\/p><\/blockquote>\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 Below are the ways to check if the given four points form quadruple in python:<\/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 Given four points, the task is to check if the given four points form quadruple in python. Quadruple: It is defined as a tuple of integers a, b, c, and d such that a2 + b2\u00a0 + c2\u00a0= d2. They are, in fact, Diophantine Equations solutions. It represents a cuboid with integer side lengths |a|, …<\/p>\nGiven first point = 6\r\nGiven second point = 2\r\nGiven third point = 3\r\nGiven fourth point = 7<\/pre>\n
The given four points { 6 , 2 , 3 , 7 } forms a quadruple<\/pre>\n
Given first point = 9\r\nGiven second point = 2\r\nGiven third point = 6 \r\nGiven fourth point = 11<\/pre>\n
The given four points { 9 , 2 , 6 , 11 } forms a quadruple<\/pre>\n
Program for Pythagorean Quadruple in Python<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Give the first number as static input and store it in a variable.\r\np = 6\r\n# Give the second number as static input and store it in another variable.\r\nq = 2\r\n# Give the third number as static input and store it in another variable.\r\nr = 3\r\n# Give the fourth number as static input and store it in another variable.\r\ns = 7\r\n# Calculate the sum of squares of the given three numbers\u00a0using the above given\r\n# mathematical formula and store it in another variable.\r\nrslt_sum = p * p + q * q + r * r\r\n# Check if the above result sum is equal to the square of the fourth number\u00a0\r\n# using the if conditional statement.\r\nif (s * s == rslt_sum):\r\n # If it is true, then print \"The given four points forms a quadruple\".\r\n print(\"The given four points {\", p, \",\", q,\r\n \",\", r, \",\", s, \"} forms a quadruple\")\r\n# Else print \"The given four points do not form a quadruple\".\r\nelse:\r\n print(\"The given four points {\", p, \",\", q,\r\n \",\", r, \",\", s, \"} do not form a quadruple\")\r\n<\/pre>\n
# include <iostream>\r\n\r\nusing namespace std\r\n\r\nint main() {\r\n double p = 6\r\n double q = 12\r\n double r = 3\r\n double s = 7\r\n double rslt_sum = p * p + q * q + r * r\r\n if ((s * s == rslt_sum)) {\r\n cout << \"The given four points {\" << p << \",\" << q << \",\" << r << \",\" << s << \"} forms a quadruple\" << endl\r\n }\r\n else {\r\n cout << \"The given four points {\" << p << \",\" << q << \",\" << r << \",\" << s << \"} do not form a quadruple\" << endl\r\n }\r\n\r\n}\r\n<\/pre>\n
The given four points { 6 , 2 , 3 , 7 } forms a quadruple<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Give the first number as user input using the int(input()) function and store it in a variable.\r\np = int(input(\"Enter some random number = \"))\r\n# Give the second number as user input using the int(input()) function and store it in another variable.\r\nq = int(input(\"Enter some random number = \"))\r\n# Give the third number as user input using the int(input()) function and store it in another variable.\r\nr = int(input(\"Enter some random number = \"))\r\n# Give the fourth number as user input using the int(input()) function and store it in another variable.\r\ns = int(input(\"Enter some random number = \"))\r\n# Calculate the sum of squares of the given first three numbers using the above given\r\n# mathematical formula and store it in another variable.\r\nrslt_sum = p * p + q * q + r * r\r\n# Check if the above result sum is equal to the square of the fourth number\r\n# using the if conditional statement.\r\nif (s * s == rslt_sum):\r\n # If it is true, then print \"The given four points forms a quadruple\".\r\n print(\"The given four points {\", p, \",\", q,\r\n \",\", r, \",\", s, \"} forms a quadruple\")\r\n# Else print \"The given four points do not form a quadruple\".\r\nelse:\r\n print(\"The given four points {\", p, \",\", q,\r\n \",\", r, \",\", s, \"} do not form a quadruple\")\r\n<\/pre>\n
Enter some random number = 9\r\nEnter some random number = 2\r\nEnter some random number = 6\r\nEnter some random number = 11\r\nThe given four points { 9 , 2 , 6 , 11 } forms a quadruple<\/pre>\n","protected":false},"excerpt":{"rendered":"