
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 if given number is perfect square in Python
Suppose we have a number n. We have to check whether the number n is perfect square or not. A number is said to be a perfect square number when its square root is an integer.
So, if the input is like n = 36, then the output will be True as 36 = 6*6.
To solve this, we will follow these steps −
- sq_root := integer part of (square root of n)
- return true when sq_root^2 is same as n otherwise false
Example
Let us see the following implementation to get better understanding −
from math import sqrt def solve(n): sq_root = int(sqrt(n)) return (sq_root*sq_root) == n n = 36 print (solve(n))
Input
36
Output
True
- Related Questions & Answers
- Check if a number is perfect square without finding square root in C++
- Python Program to Check if a Number is a Perfect Number
- Check if product of array containing prime numbers is a perfect square in Python
- Check Perfect Square or Not
- Program to check number is perfect square or not without sqrt function in Python
- Check for perfect square in JavaScript
- Golang Program to Check if a Number is a Perfect Number
- Check if given number is Emirp Number or not in Python
- Check whether the number can be made perfect square after adding 1 in Python
- Check whether the number formed by concatenating two numbers is a perfect square or not in Python
- C program to find if the given number is perfect number or not
- Python program to check if the given number is Happy Number
- Find the Next perfect square greater than a given number in C++
- Check if the given number is Ore number or not in Python
- Check if given four points form a Square
Advertisements