
- 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 whether the number can be made perfect square after adding 1 in Python
Suppose we have a number n. We have to check whether the number can be a perfect square number by adding 1 with it or not.
So, if the input is like n = 288, then the output will be True as after adding 1, it becomes 289 which is same as 17^2.
To solve this, we will follow these steps −
- res_num := n + 1
- 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(n): res_num = n + 1 sqrt_val = int(sqrt(res_num)) if sqrt_val * sqrt_val == res_num: return True return False n = 288 print(solve(n))
Input
288
Output
True
- Related Questions & Answers
- Check if given number is perfect square in Python
- Check whether the number formed by concatenating two numbers is a perfect square or not in Python
- Check Perfect Square or Not
- Check whether given string can be generated after concatenating given strings in Python
- Check for perfect square in JavaScript
- Check if a number is perfect square without finding square root in C++
- Program to check whether one string can be 1-to-1 mapped into another string in Python
- Program to check number is perfect square or not without sqrt function in Python
- Check whether the file can be read in Java
- Find minimum number to be divided to make a number a perfect square in C++
- 8086 program to find the square root of a perfect square root number
- Program to check whether palindrome can be formed after deleting at most k characters or not in python
- Check if a two-character string can be made using given words in Python
- Check for perfect square without using Math libraries - JavaScript
- Count number of bits changed after adding 1 to given N in C++
Advertisements