{"id":16971,"date":"2021-08-17T08:47:57","date_gmt":"2021-08-17T03:17:57","guid":{"rendered":"https:\/\/python-programs.com\/?p=16971"},"modified":"2021-11-22T18:37:23","modified_gmt":"2021-11-22T13:07:23","slug":"python-program-to-check-tech-number-or-not","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-tech-number-or-not\/","title":{"rendered":"Python Program to Check Tech Number or Not"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Check Buzz Number or Not<\/a> A number is referred to as a tech number if it has an even number of digits and can be divided exactly into two parts from the middle. After evenly dividing the number, add the numbers together and find the square of the sum. If we get the number as a square, we know it’s a tech number; otherwise, it’s not.<\/p>\n Example:<\/p>\n Let the number = 2025<\/p>\n #divide the number into two equal parts<\/p>\n first part = 20<\/p>\n second part = 25<\/p>\n sum = first part + second part = 20 +25 = 45<\/p>\n #square the obtained ‘sum ‘<\/p>\n square_sum = 45*45 = 2025 (which is equal to given number).<\/p>\n Therefore 2025 is a tech number.<\/p>\n Note:<\/strong> The basic condition for checking the tech number is that it has an even number of digits. If this is the case, we will proceed to the next step; otherwise, the code will not be executed further.<\/p>\n Examples:<\/strong><\/p>\n Example 1:<\/strong><\/p>\n Input:\u00a0<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:\u00a0<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to if the given number is a Tech number or not.<\/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 instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Check Buzz Number or Not Tech number : A number is referred to as a tech number if it has an even number of digits and can be divided exactly into two parts from the middle. After evenly dividing the number, add the numbers together …<\/p>\n
\nTech number :<\/strong><\/p>\nGiven Number = 2025<\/pre>\n
The Given Number { 2025 } is Tech number<\/pre>\n
Given Number = 2025<\/pre>\n
The Given Number { 1800 } is Not a Tech number<\/pre>\n
Program to Check Tech Number or Not<\/h2>\n
\n
Method #1: Using Slicing (Static input)<\/h3>\n
\n
# Give the number as static input and store it in a variable.\r\nn = 2025\r\n# Convert the given number into the string using the built-in str() function\r\n# and store it in another variable.\r\ns = str(n)\r\n# Calculate the length of the above string using the len() function\u00a0and\r\n# store it in another variable.\r\nl = len(s)\r\n# Check if the length of the given number is even or not by using the\r\n# if conditional statement.\r\nif(l % 2 == 0):\r\n # If the statement is True, divide the given number into two equal halves using the slicing.\r\n # Store it in two different variables say 'first_half ' and 'second_half'.\r\n fst_half = s[:l\/\/2]\r\n scnd_half = s[l\/\/2:]\r\n# Calculate the sum of both the halves by converting string to int using int() function\r\n# and store it in a variable say \"total sum\".\r\n tot_sum = (int(fst_half)+int(scnd_half))\r\n# Multiply the \"total sum\" with itself and store it in another variable.\r\n square_sum = tot_sum*tot_sum\r\n # Check if the \"total sum\" is equal to the given input number using the\r\n # if conditional statement.\r\n if(n == square_sum):\r\n # If the statement is True, then print \"Tech number\".\r\n print(\"The Given Number {\", n, \"} is Tech number\")\r\n else:\r\n # Else print \"Not a Tech number\".\r\n print(\"The Given Number {\", n, \"} is Not a Tech number\")\r\n# If the length of the given number is odd, then Print \"Not a tech Number\".\r\nelse:\r\n print(\"The Given Number {\", n, \"} is Not a Tech number\")\r\n<\/pre>\n
The Given Number { 2025 } is Tech number<\/pre>\n
Method #2: Using Slicing (User input)<\/h3>\n
\n
# Give the number as user input using int(input()) and store it in a variable.\r\nn = int(input(\"Enter some random number = \"))\r\n# Convert the given number into the string using the built-in str() function\r\n# and store it in another variable.\r\ns = str(n)\r\n# Calculate the length of the above string using the len() function\u00a0and\r\n# store it in another variable.\r\nl = len(s)\r\n# Check if the length of the given number is even or not by using the\r\n# if conditional statement.\r\nif(l % 2 == 0):\r\n # If the statement is True, divide the given number into two equal halves using the slicing.\r\n # Store it in two different variables say 'first_half ' and 'second_half'.\r\n fst_half = s[:l\/\/2]\r\n scnd_half = s[l\/\/2:]\r\n# Calculate the sum of both the halves by converting string to int using int() function\r\n# and store it in a variable say \"total sum\".\r\n tot_sum = (int(fst_half)+int(scnd_half))\r\n# Multiply the \"total sum\" with itself and store it in another variable.\r\n square_sum = tot_sum*tot_sum\r\n # Check if the \"total sum\" is equal to the given input number using the\r\n # if conditional statement.\r\n if(n == square_sum):\r\n # If the statement is True, then print \"Tech number\".\r\n print(\"The Given Number {\", n, \"} is Tech number\")\r\n else:\r\n # Else print \"Not a Tech number\".\r\n print(\"The Given Number {\", n, \"} is Not a Tech number\")\r\n# If the length of the given number is odd, then Print \"Not a tech Number\".\r\nelse:\r\n print(\"The Given Number {\", n, \"} is Not a Tech number\")\r\n<\/pre>\n
Enter some random number = 9801\r\nThe Given Number { 9801 } is Tech number<\/pre>\n
\n