{"id":22848,"date":"2021-09-29T22:32:24","date_gmt":"2021-09-29T17:02:24","guid":{"rendered":"https:\/\/python-programs.com\/?p=22848"},"modified":"2021-11-22T18:35:34","modified_gmt":"2021-11-22T13:05:34","slug":"python-program-for-minimum-height-of-a-triangle-with-given-base-and-area","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-minimum-height-of-a-triangle-with-given-base-and-area\/","title":{"rendered":"Python Program for Minimum Height of a Triangle with Given Base and Area"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Calculate Volume and Surface Area of Hemisphere<\/a> Knowing the relationship between the three allows you to calculate the minimum height of a triangle with base “b” and area “a.”<\/p>\n The relationship between area, base, and height:<\/p>\n area = (1\/2) * base * height<\/strong><\/p>\n As a result, height can be calculated as follows:<\/p>\n height = (2 * area)\/ base<\/strong><\/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 find the minimum height so that a triangle of least area a<\/strong> and base b<\/strong> can be formed:<\/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 If you are learning Python then the Python Programming Example<\/a> is for you and gives you a thorough description of concepts for beginners, experienced programmers.<\/p>\n In the previous article, we have discussed Python Program to Calculate Volume and Surface Area of Hemisphere Given the area(a) and the base(b) of the triangle, the task is to find the minimum height so that a triangle of least area a and base b can be formed. Knowing the relationship between the three allows …<\/p>\n
\nGiven the area(a) and the base(b) of the triangle, the task is to find the minimum height so that a triangle of least area a<\/strong> and base b<\/strong> can be formed.<\/p>\nGiven area = 6\r\nGiven base = 3<\/pre>\n
The minimum height so that a triangle of the least area and base can be formed = 4<\/pre>\n
Given area = 7\r\nGiven base = 5<\/pre>\n
The minimum height so that a triangle of the least area and base can be formed = 3<\/pre>\n
Program for Minimum Height of a Triangle with Given Base and Area 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 Smallest_height() which takes the given area and base\r\n# of the triangle as the arguments and returns the minimum height so that a\r\n# triangle of least area and base can be formed.\r\n\r\n\r\ndef Smallest_height(gvn_areaoftri, gvn_baseoftri):\r\n # Inside the function, calculate the value of (2*gvn_areaoftri)\/gvn_baseoftri using\r\n # the above mathematical formula and store it in another variable.\r\n rslt = (2*gvn_areaoftri)\/gvn_baseoftri\r\n # Apply math.ceil() function to the above result and return the minimum height.\r\n return math.ceil(rslt)\r\n\r\n\r\n# Give the area as static input and store it in a variable.\r\ngvn_areaoftri = 6\r\n# Give the base as static input and store it in another variable.\r\ngvn_baseoftri = 3\r\n# Pass the given area and base of the triangle as the arguments to the Smallest_height()\r\n# function and store it in a variable.\r\nmin_heigt = Smallest_height(gvn_areaoftri, gvn_baseoftri)\r\n# Print the above result i.e, minimum height so that a triangle of the least area\r\n# and base can be formed.\r\nprint(\"The minimum height so that a triangle of the least area and base can be formed = \", min_heigt)\r\n<\/pre>\n
The minimum height so that a triangle of the least area and base can be formed = 4<\/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 Smallest_height() which takes the given area and base\r\n# of the triangle as the arguments and returns the minimum height so that a\r\n# triangle of least area and base can be formed.\r\n\r\n\r\ndef Smallest_height(gvn_areaoftri, gvn_baseoftri):\r\n # Inside the function, calculate the value of (2*gvn_areaoftri)\/gvn_baseoftri using\r\n # the above mathematical formula and store it in another variable.\r\n rslt = (2*gvn_areaoftri)\/gvn_baseoftri\r\n # Apply math.ceil() function to the above result and return the minimum height.\r\n return math.ceil(rslt)\r\n\r\n\r\n# Give the area as user input using the int(input()) function and store it in a variable.\r\ngvn_areaoftri = int(input(\"Enter some random number = \"))\r\n# Give the base as user input using the int(input()) function and \r\n# store it in another variable.\r\ngvn_baseoftri = int(input(\"Enter some random number = \"))\r\n# Pass the given area and base of the triangle as the arguments to the Smallest_height()\r\n# function and store it in a variable.\r\nmin_heigt = Smallest_height(gvn_areaoftri, gvn_baseoftri)\r\n# Print the above result i.e, minimum height so that a triangle of the least area\r\n# and base can be formed.\r\nprint(\"The minimum height so that a triangle of the least area and base can be formed = \", min_heigt)\r\n<\/pre>\n
Enter some random number = 7\r\nEnter some random number = 5\r\nThe minimum height so that a triangle of the least area and base can be formed = 3<\/pre>\n
\n