
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Check whether the number formed by concatenating two numbers is a perfect square or not in Python
Suppose we have two numbers x and y. We have to concatenate them and check whether the resultant number is perfect square or not.
So, if the input is like x = 2 y = 89, then the output will be True as after concatenating the number will be 289 which is 17^2.
To solve this, we will follow these steps −
- first_num := x as string
- second_num := y as string
- res_num := concatenate first_num and second_num then convert to integer
- sqrt_val := integer part of square root of(res_num)
- if sqrt_val * sqrt_val is same as res_num, then
- return True
- return False
Let us see the following implementation to get better understanding −
Example Code
from math import sqrt def solve(x, y): first_num = str(x) second_num = str(y) res_num = int(first_num + second_num) sqrt_val = int(sqrt(res_num)) if sqrt_val * sqrt_val == res_num: return True return False x = 2 y = 89 print(solve(x, y))
Input
2, 89
Output
True
- Related Articles
- Check Perfect Square or Not
- Program to check number is perfect square or not without sqrt function in Python
- Swift Program to Check whether a number is a Perfect Cube or not
- Program to check whether two trees can be formed by swapping nodes or not in Python
- Check whether the given number is Euclid Number or not in Python
- Check if given number is perfect square in Python
- Check whether the number can be made perfect square after adding 1 in Python
- Check whether N is a Dihedral Prime Number or not in Python
- Check whether the given number is Wagstaff prime or not in Python
- Check if a number in a list is perfect square using Python
- How to check whether a number is prime or not using Python?
- Program to check whether given number is Narcissistic number or not in Python
- Check whether a given number is Polydivisible or Not
- Check Whether a Number is a Coprime Number or Not in Java
- Check whether a number is a Fibonacci number or not JavaScript

Advertisements