Python Program to Check Tech Number or Not

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 in python 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. What is Special Number Program In Python, Tech Number Example, Tech Number Program In Java, Tech Numbers, Examples Of Tech Number, Neon Number Program In Java, A Tech Number Has Even Number Of Digits.

Example:

Let the number = 2025

#divide the number into two equal parts

first part = 20

second part = 25

sum = first part + second part = 20 +25 = 45

#square the obtained ‘sum ‘

square_sum = 45*45 = 2025 (which is equal to given number).

Therefore 2025 is a tech number.

Note: 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.

Examples:

Example 1:

Input: 

Given Number = 2025

Output:

The Given Number { 2025 } is Tech number

Example 2:

Input: 

Given Number = 2025

Output:

The Given Number { 1800 } is Not a Tech number

Program to Check Tech Number or Not

Below are the ways to if the given number is a Tech number or not.

Method #1: Using Slicing (Static input)

Approach:

  • Give the number as static input and store it in a variable.
  • Convert the given number into the string using the built-in str() function and store it in another variable.
  • Calculate the length of the above string using the len() function and store it in another variable.
  • Check if the length of the given number is even or not by using the if conditional statement.
  • If the statement is True, divide the given number into two equal halves using the slicing.
  • Store it in two different variables say ‘first_half ‘ and ‘second_half’.
  • Calculate the sum of both the halves by converting string to int using int() function and store it in a variable say “total sum”.
  • Multiply the “total sum” with itself and store it in another variable.
  • Check if the “total sum” is equal to the given input number using the if conditional statement.
  • If the statement is True, then print “Tech Number”.
  • Else print “Not a Tech number”.
  • If the length of the given number is odd, then Print “Not a Tech Number”.
  • The Exit of the program.

Below is the implementation:

# Give the number as static input and store it in a variable.
n = 2025
# Convert the given number into the string using the built-in str() function
# and store it in another variable.
s = str(n)
# Calculate the length of the above string using the len() function and
# store it in another variable.
l = len(s)
# Check if the length of the given number is even or not by using the
# if conditional statement.
if(l % 2 == 0):
    # If the statement is True, divide the given number into two equal halves using the slicing.
    # Store it in two different variables say 'first_half ' and 'second_half'.
    fst_half = s[:l//2]
    scnd_half = s[l//2:]
# Calculate the sum of both the halves by converting string to int using int() function
# and store it in a variable say "total sum".
    tot_sum = (int(fst_half)+int(scnd_half))
# Multiply the "total sum" with itself and store it in another variable.
    square_sum = tot_sum*tot_sum
 # Check if the "total sum" is equal to the given input number using the
 # if conditional statement.
    if(n == square_sum):
           # If the statement is True, then print "Tech number".
        print("The Given Number {", n, "} is Tech number")
    else:
       # Else print "Not a Tech number".
        print("The Given Number {", n, "} is Not a Tech number")
# If the length of the given number is odd, then Print "Not a tech Number".
else:
    print("The Given Number {", n, "} is Not a Tech number")

Output:

The Given Number { 2025 } is Tech number

Method #2: Using Slicing (User input)

Approach:

  • Give the number as user input using the int(input()) function and store it in a variable.
  • Convert the given number into the string using the built-in str() function and store it in another variable.
  • Calculate the length of the above string using the len() function and store it in another variable.
  • Check if the length of the given number is even or not by using the if conditional statement.
  • If the statement is True, divide the given number into two equal halves using the slicing.
  • Store it in two different variables say ‘first_half ‘ and ‘second_half’.
  • Calculate the sum of both the halves by converting string to int using int() function and store it in a variable say “total sum”.
  • Multiply the “total sum” with itself and store it in another variable.
  • Check if the “total sum” is equal to the given input number using the if conditional statement.
  • If the statement is True, then print “Tech Number”.
  • Else print “Not a Tech number”.
  • If the length of the given number is odd, then Print “Not a Tech Number”.
  • The Exit of the program.

Below is the implementation:

# Give the number as user input using int(input()) and store it in a variable.
n = int(input("Enter some random number = "))
# Convert the given number into the string using the built-in str() function
# and store it in another variable.
s = str(n)
# Calculate the length of the above string using the len() function and
# store it in another variable.
l = len(s)
# Check if the length of the given number is even or not by using the
# if conditional statement.
if(l % 2 == 0):
    # If the statement is True, divide the given number into two equal halves using the slicing.
    # Store it in two different variables say 'first_half ' and 'second_half'.
    fst_half = s[:l//2]
    scnd_half = s[l//2:]
# Calculate the sum of both the halves by converting string to int using int() function
# and store it in a variable say "total sum".
    tot_sum = (int(fst_half)+int(scnd_half))
# Multiply the "total sum" with itself and store it in another variable.
    square_sum = tot_sum*tot_sum
 # Check if the "total sum" is equal to the given input number using the
 # if conditional statement.
    if(n == square_sum):
           # If the statement is True, then print "Tech number".
        print("The Given Number {", n, "} is Tech number")
    else:
       # Else print "Not a Tech number".
        print("The Given Number {", n, "} is Not a Tech number")
# If the length of the given number is odd, then Print "Not a tech Number".
else:
    print("The Given Number {", n, "} is Not a Tech number")

Output:

Enter some random number = 9801
The Given Number { 9801 } is Tech number

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.

Also check: 

  1. What Is A Tech Number
  2. Write A Program To Check Special Number In Python

Related Posts On