{"id":22749,"date":"2021-09-27T15:43:14","date_gmt":"2021-09-27T10:13:14","guid":{"rendered":"https:\/\/python-programs.com\/?p=22749"},"modified":"2021-11-22T18:35:37","modified_gmt":"2021-11-22T13:05:37","slug":"python-program-for-maximum-number-of-2x2-squares-that-can-be-fit-inside-a-right-isosceles-triangle","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-maximum-number-of-2x2-squares-that-can-be-fit-inside-a-right-isosceles-triangle\/","title":{"rendered":"Python Program for Maximum Number of 2\u00d72 Squares That Can be Fit Inside a Right Isosceles Triangle"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find Slope of a Line<\/a> The side of the square must be parallel to the base of the given isosceles triangle.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n <\/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 2*2 squares required that can be fixed 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 Find a comprehensive collection of Examples of Python Programs<\/a> ranging from simple ones to complex ones to guide you throughout your coding journey.<\/p>\n In the previous article, we have discussed Python Program to Find Slope of a Line Given the base of the isosceles triangle, the task is to find the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle. The side of the square must be parallel to …<\/p>\n
\nGiven the base of the isosceles triangle, the task is to find the count of the maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle.<\/p>\nGiven base of triangle = 8<\/pre>\n
The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = 6<\/pre>\n
Given base of triangle = 6<\/pre>\n
The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = 3<\/pre>\n
Program for Maximum Number of 2\u00d72 Squares That Can be Fit Inside a Right Isosceles Triangle in python:<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Create a function to say count_Squares() which takes the given base of the isosceles\r\n# triangle as an argument and returns the count of the maximum number of 2*2\r\n# squares required that can be fixed inside the given isosceles triangle.\r\n\r\n\r\ndef count_Squares(gvn_trianglebase):\r\n # Inside the function, subtract 2 from the given base value as it is the extra part.\r\n # Store it in the same variable.\r\n\r\n gvn_trianglebase = (gvn_trianglebase - 2)\r\n # Divide the given base of the triangle by 2 since each square has a base length of 2.\r\n # Store it in the same variable.\r\n gvn_trianglebase = gvn_trianglebase \/\/ 2\r\n # Calculate the value of gvn_trianglebase * (gvn_trianglebase + 1) \/ 2\r\n # (Mathematical Formula) and store it in another variable.\r\n rslt = gvn_trianglebase * (gvn_trianglebase + 1) \/\/ 2\r\n # Return the above result which is the count of the maximum number of 2*2 squares\r\n # required that can be fixed inside the given isosceles triangle.\r\n return rslt\r\n\r\n\r\n# Give the base of the triangle as static input and store it in a variable.\r\ngvn_trianglebase = 6\r\n# Pass the given base of the isosceles triangle to the count_Squares() function\r\n# and print it.\r\nprint(\"The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = \",\r\n count_Squares(gvn_trianglebase))\r\n<\/pre>\n
The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = 3<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Create a function to say count_Squares() which takes the given base of the isosceles\r\n# triangle as an argument and returns the count of the maximum number of 2*2\r\n# squares required that can be fixed inside the given isosceles triangle.\r\n\r\n\r\ndef count_Squares(gvn_trianglebase):\r\n # Inside the function, subtract 2 from the given base value as it is the extra part.\r\n # Store it in the same variable.\r\n\r\n gvn_trianglebase = (gvn_trianglebase - 2)\r\n # Divide the given base of the triangle by 2 since each square has a base length of 2.\r\n # Store it in the same variable.\r\n gvn_trianglebase = gvn_trianglebase \/\/ 2\r\n # Calculate the value of gvn_trianglebase * (gvn_trianglebase + 1) \/ 2\r\n # (Mathematical Formula) and store it in another variable.\r\n rslt = gvn_trianglebase * (gvn_trianglebase + 1) \/\/ 2\r\n # Return the above result which is the count of the maximum number of 2*2 squares\r\n # required that can be fixed inside the given isosceles triangle.\r\n return rslt\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_trianglebase = int(input(\"Enter some random number = \"))\r\n# Pass the given base of the isosceles triangle to the count_Squares() function\r\n# and print it.\r\nprint(\"The maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = \",\r\n count_Squares(gvn_trianglebase))\r\n<\/pre>\n
Enter some random number = 8\r\nThe maximum number of 2*2 squares required that can be fixed inside the given isosceles triangle = 6<\/pre>\n
\n