{"id":22850,"date":"2021-09-29T20:13:21","date_gmt":"2021-09-29T14:43:21","guid":{"rendered":"https:\/\/python-programs.com\/?p=22850"},"modified":"2021-11-22T18:35:37","modified_gmt":"2021-11-22T13:05:37","slug":"python-program-for-maximum-number-of-squares-that-can-fit-in-a-right-angle-isosceles-triangle","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-maximum-number-of-squares-that-can-fit-in-a-right-angle-isosceles-triangle\/","title":{"rendered":"Python Program for Maximum Number of Squares that Can Fit in a Right Angle Isosceles Triangle"},"content":{"rendered":"
In the previous article, we have discussed Python Program for Minimum Height of a Triangle with Given Base and Area<\/a> Formula:<\/strong><\/p>\n (b \/ m \u2013 1) * (b \/ m) \/ 2<\/strong><\/p>\n where b is the base of an isosceles triangle.<\/p>\n m is the sidelength of the square.<\/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 count of the maximum number of squares of side length m<\/strong> that can be fitted inside the given isosceles triangle.<\/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 Explore more Example Python Programs<\/a> with output and explanation and practice them for your interviews, assignments and stand out from the rest of the crowd.<\/p>\n In the previous article, we have discussed Python Program for Minimum Height of a Triangle with Given Base and Area Given the base b of an isosceles triangle and a value m, the task is to find the count of the maximum number of squares of side length m that can be fitted inside the …<\/p>\n
\nGiven the base b<\/strong> of an isosceles triangle and a value m<\/strong>, the task is to find the count of the maximum number of squares of side length m<\/strong> that can be fitted inside the given isosceles triangle.<\/p>\nGiven base of triangle = 8\r\nGiven side of square = 3<\/pre>\n
The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = \r\n2<\/pre>\n
Given base of triangle = 5\r\nGiven side of square = 2<\/pre>\n
The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = \r\n1<\/pre>\n
Program for Maximum Number of Squares that Can Fit in a Right Angle Isosceles Triangle in Python<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Create a function to say count_maximumsqures() which takes the given base of the\r\n# isosceles triangle and side of the square as the arguments and returns the\r\n# count of the maximum number of squares of the given sidelength required that\r\n# can be fitted inside the given isosceles triangle.\r\n\r\n\r\ndef count_maximumsqures(gvn_base, squre_side):\r\n # Inside the function, calculate the count of the maximum number of squares using the\r\n # above mathematical formula and store it in a variable.\r\n cnt = (gvn_base \/ squre_side - 1) * (gvn_base \/ squre_side) \/ 2\r\n # Return the above count value.\r\n return cnt\r\n\r\n\r\n# Give the base of the triangle as static input and store it in a variable.\r\ngvn_base = 8\r\n# Give the side of the square as static input and store it in another variable.\r\nsqure_side = 3\r\nprint(\"The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = \")\r\n# Pass the given base of the isosceles triangle and side of the square as the arguments\r\n# to the count_maximumsqures() function, convert it into Integer using int()\r\n# function, and print it.\r\nprint(int(count_maximumsqures(gvn_base, squre_side)))\r\n<\/pre>\n
The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = \r\n2<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Create a function to say count_maximumsqures() which takes the given base of the\r\n# isosceles triangle and side of the square as the arguments and returns the\r\n# count of the maximum number of squares of the given sidelength required that\r\n# can be fitted inside the given isosceles triangle.\r\n\r\n\r\ndef count_maximumsqures(gvn_base, squre_side):\r\n # Inside the function, calculate the count of the maximum number of squares using the\r\n # above mathematical formula and store it in a variable.\r\n cnt = (gvn_base \/ squre_side - 1) * (gvn_base \/ squre_side) \/ 2\r\n # Return the above count value.\r\n return cnt\r\n\r\n\r\n# Give the base of the triangle as user input using the int(input()) function\r\n# and store it in a variable.\r\ngvn_base = int(input(\"Enter some random number = \"))\r\n# Give the side of the square as user input using the int(input()) function and \r\n# store it in another variable.\r\nsqure_side = int(input(\"Enter some random number = \"))\r\nprint(\"The maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = \")\r\n# Pass the given base of the isosceles triangle and side of the square as the arguments\r\n# to the count_maximumsqures() function, convert it into Integer using int()\r\n# function, and print it.\r\nprint(int(count_maximumsqures(gvn_base, squre_side)))\r\n\r\n\r\n<\/pre>\n
Enter some random number = 5\r\nEnter some random number = 2\r\nThe maximum number of squares with given sidelength that can be fitted inside the isosceles triangle = \r\n1<\/pre>\n
\n