Problem Set 6(Autocube numbers)

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

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

Output:
Display whether the number is a autocube or not

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

Algorithm:
Step1. Define the function autocube 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 autocube else display autocube
Step2. get the number n
Step3. Call the function autocube to check if n is a autocube 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...