Practice Problem 6-Heterocube
Practice Problem 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
Borgata Hotel Casino & Spa - Mapyro
ReplyDeleteBorgata Hotel 전라북도 출장마사지 Casino & Spa · Bally's Atlantic 태백 출장안마 City · MGM Grand Hotel 광양 출장안마 & Casino · Caesars 여주 출장샵 Atlantic 성남 출장마사지 City · MGM Grand · Harrah's Atlantic City.