{"id":23774,"date":"2021-10-03T20:27:20","date_gmt":"2021-10-03T14:57:20","guid":{"rendered":"https:\/\/python-programs.com\/?p=23774"},"modified":"2021-11-22T18:33:25","modified_gmt":"2021-11-22T13:03:25","slug":"python-program-to-calculate-area-and-volume-of-a-tetrahedron","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-area-and-volume-of-a-tetrahedron\/","title":{"rendered":"Python Program to Calculate Area and Volume of a Tetrahedron"},"content":{"rendered":"
Tetrahedron:<\/strong><\/p>\n A Tetrahedron is nothing more than a pyramid with a triangular base. It has four triangular faces, three on the sides or lateral faces, one on the bottom or base, and four vertices or corners. If all of the faces are congruent equilateral triangles, the tetrahedron is said to be regular.<\/p>\n Formula:<\/strong><\/p>\n Area of Tetrahedron =sqrt(3)*side*side<\/p>\n Volume = (side<\/span>\u00a0**<\/span> 3<\/span> \/<\/span> (<\/span>6<\/span> *<\/span> math.<\/span>sqrt(<\/span>2<\/span>)<\/span>)<\/span>)<\/span><\/p><\/blockquote>\n Given the side of a tetrahedron and the task is to calculate the area and volume of the given tetrahedron in python.<\/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 Below are the ways to calculate the area and volume of the given tetrahedron 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 Tetrahedron: A Tetrahedron is nothing more than a pyramid with a triangular base. It has four triangular faces, three on the sides or lateral faces, one on the bottom or base, and four vertices or corners. If all of the faces are congruent equilateral triangles, the tetrahedron is said to be regular. Formula: Area of …<\/p>\nGiven side = 5<\/pre>\n
The Area of Tetrahedron with the given side { 5 } = 43.301\r\nThe volume of Tetrahedron with the given side { 5 } = 14.731<\/pre>\n
Given side = 10<\/pre>\n
The Area of Tetrahedron with the given side { 10 } = 173.205\r\nThe volume of Tetrahedron with the given side { 10 } = 117.851<\/pre>\n
Program to Calculate Area and Volume of a Tetrahedron in Python<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n\r\n# Create a function to say TetrahedronArea() which takes the given side as an argument\r\n# and returns the area of the given tetrahedron.\r\n\r\n\r\ndef TetrahedronArea(gvn_side):\r\n # Inside the function, calculate the area of a given tetrahedron using the above\r\n # given mathematical formula and math.sqrt() function.\r\n # Store it in a variable.\r\n rslt_area = math.sqrt(3) * (gvn_side * gvn_side)\r\n # Return the above result.\r\n return rslt_area\r\n\r\n# Create another function to say Tetrahedronvolume() which takes the given side as an\r\n# argument and returns the volume of the given tetrahedron.\r\n\r\n\r\ndef Tetrahedronvolume(gvn_side):\r\n # Inside the function, calculate the volume of a given tetrahedron using the above\r\n # given mathematical formula and math.sqrt() function.\r\n # Store it in a variable.\r\n rslt_vol = (gvn_side ** 3 \/ (6 * math.sqrt(2)))\r\n # Return the above result.\r\n return rslt_vol\r\n\r\n\r\n# Give the side as static input and store it in a variable.\r\ngvn_side = 10\r\n# Pass the given side as an argument to the TetrahedronArea() function and round it\r\n# off to up to 3 places after the decimal point using the round() function.\r\n# Store it in another variable.\r\narea_tetrahdrn = round(TetrahedronArea(gvn_side), 3)\r\n# Print the above result which is the area of the given tetrahedron.\r\nprint(\r\n \"The Area of Tetrahedron with the given side {\", gvn_side, \"} = \", area_tetrahdrn)\r\n# Pass the given side as an argument to the Tetrahedronvolume() function and round it off\r\n# to up to 3 places after the decimal point using the round() function.\r\n# Store it in another variable.\r\nvolum_tetrahdrn = round(Tetrahedronvolume(gvn_side), 3)\r\n# Print the above result which is the volume of the given tetrahedron.\r\nprint(\r\n \"The volume of Tetrahedron with the given side {\", gvn_side, \"} = \", volum_tetrahdrn)\r\n<\/pre>\n
#include <cmath>\r\n#include <iostream>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n int gvn_side = 10;\r\n double area_tetrahdrn = sqrt(3) * (gvn_side * gvn_side);\r\n double volum_tetrahdrn\r\n = (pow(gvn_side, 3) \/ (6 * sqrt(2)));\r\n cout << \"The Area of Tetrahedron with the given side {\"\r\n << gvn_side << \"} = \" << area_tetrahdrn << endl;\r\n cout\r\n << \"The Volume of Tetrahedron with the given side {\"\r\n << gvn_side << \"} = \" << volum_tetrahdrn << endl;\r\n return 0;\r\n}<\/pre>\n
The Area of Tetrahedron with the given side { 10 } = 173.205\r\nThe volume of Tetrahedron with the given side { 10 } = 117.851<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n\r\n# Create a function to say TetrahedronArea() which takes the given side as an argument\r\n# and returns the area of the given tetrahedron.\r\n\r\n\r\ndef TetrahedronArea(gvn_side):\r\n # Inside the function, calculate the area of a given tetrahedron using the above\r\n # given mathematical formula and math.sqrt() function.\r\n # Store it in a variable.\r\n rslt_area = math.sqrt(3) * (gvn_side * gvn_side)\r\n # Return the above result.\r\n return rslt_area\r\n\r\n# Create another function to say Tetrahedronvolume() which takes the given side as an\r\n# argument and returns the volume of the given tetrahedron.\r\n\r\n\r\ndef Tetrahedronvolume(gvn_side):\r\n # Inside the function, calculate the volume of a given tetrahedron using the above\r\n # given mathematical formula and math.sqrt() function.\r\n # Store it in a variable.\r\n rslt_vol = (gvn_side ** 3 \/ (6 * math.sqrt(2)))\r\n # Return the above result.\r\n return rslt_vol\r\n\r\n\r\n# Give the side as user input using the int(input()) function and store it in a variable.\r\ngvn_side = int(input(\"Enter some random number = \"))\r\n# Pass the given side as an argument to the TetrahedronArea() function and round it\r\n# off to up to 3 places after the decimal point using the round() function.\r\n# Store it in another variable.\r\narea_tetrahdrn = round(TetrahedronArea(gvn_side), 3)\r\n# Print the above result which is the area of the given tetrahedron.\r\nprint(\r\n \"The Area of Tetrahedron with the given side {\", gvn_side, \"} = \", area_tetrahdrn)\r\n# Pass the given side as an argument to the Tetrahedronvolume() function and round it off\r\n# to up to 3 places after the decimal point using the round() function.\r\n# Store it in another variable.\r\nvolum_tetrahdrn = round(Tetrahedronvolume(gvn_side), 3)\r\n# Print the above result which is the volume of the given tetrahedron.\r\nprint(\r\n \"The volume of Tetrahedron with the given side {\", gvn_side, \"} = \", volum_tetrahdrn)\r\n<\/pre>\n
Enter some random number = 5\r\nThe Area of Tetrahedron with the given side { 5 } = 43.301\r\nThe volume of Tetrahedron with the given side { 5 } = 14.731<\/pre>\n","protected":false},"excerpt":{"rendered":"