Autosquare numbers are numbers having "n" digits such that the square of the number contains the number itself. That is, the original number occurs in the square of the number, in some position. Write an algorithm and the subsequent Python code to check if the given number is an autosquare. Write a function to find the square of a given number. For example, 25 is a 2 digit autosquare number with a square of 625. Here the number 25 occurs in its squre and 376 with its square 141376, is a 3 digit autosquare number.
Input Format
auto square numbers:
First line contains the number to be checked
Output Format
Print Autosquare Not autosquare
Input:
The number
Processing Involved:
def autosquare(n):
length = len(str(n))
if n == int(str(n**2)[-length:]):
print('Autosquare')
else:
print('Not autosquare')
Output:
Display whether the number is autosquare or not
Program:
def autosquare(n):
length = len(str(n))
if n == int(str(n**2)[-length:]):
print('Autosquare')
else:
print('Not autosquare')
n = int(input())
autosquare(n)
Algorithm:
Step1. Define the function autosquare with one parameter n
Step1.1 assign temp as an empty string and length as length of the number n
Step1.2 check if the last n digits of the square of n is the number n if true the display autosquare else display not autosquare
Step2. get the number n
Step3. Call the function autosquare to check if n is autosquare or not
Step4. End
Input Format
auto square numbers:
First line contains the number to be checked
Output Format
Print Autosquare Not autosquare
Input:
The number
Processing Involved:
def autosquare(n):
length = len(str(n))
if n == int(str(n**2)[-length:]):
print('Autosquare')
else:
print('Not autosquare')
Output:
Display whether the number is autosquare or not
Program:
def autosquare(n):
length = len(str(n))
if n == int(str(n**2)[-length:]):
print('Autosquare')
else:
print('Not autosquare')
n = int(input())
autosquare(n)
Algorithm:
Step1. Define the function autosquare with one parameter n
Step1.1 assign temp as an empty string and length as length of the number n
Step1.2 check if the last n digits of the square of n is the number n if true the display autosquare else display not autosquare
Step2. get the number n
Step3. Call the function autosquare to check if n is autosquare or not
Step4. End
No comments:
Post a Comment