![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements