Practice Problem Set 6(Heterocube)

Q.Heterocube numbers are numbers having "n" digits such that the  last n digits of the cube  of the number will not  be the number itself. Write an algorithm and the subsequent Python code to check if the given number is heterocube.  Write a function to find the cube of a given number. For example, 22  is a 2 digit heterocube number with a cube  of 10648 and 111  with its  cube  1367631, is a 3 digit heterocube number.
Input Format
First line contains the number to be checked
Output Format
Print Heterocube or Not heterocube
Input:
The number

Processing Involved:
def heterocube(n):
    temp = ''
    length = len(str(n))
    cube = n**3
    if int(str(cube)[-length:]) == n:
        print('Not heterocube')
    else:
        print('Heterocube')

Output:
Display whether the number is a heterocube or not

Program:
def heterocube(n):
    temp = ''
    length = len(str(n))
    cube = n**3
    if int(str(cube)[-length:]) == n:
        print('Not heterocube')
    else:
        print('Heterocube')
n = int(input())
heterocube(n)

Algorithm:
Step1. Define the function heterocube with one parameter n
Step1.1 assign temp as an empty string and length as length of the number n
Step1.2 assign cube as the cube of n
Step1.3 check if the last n digits of the cube are the number n if true the display not heterocube else display heterocube
Step2. get the number n
Step3. Call the function heterocube to check if n is a hetercube or not
Step4. End


No comments:

Post a Comment

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...