Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
I want to check if a number is a perfect square or not. How we can do that?

1 Answer

0 votes
by (107k points)

You can create your own function that will evaluate weather the number is a perfect number or not:

def is_square(apositiveint):

  x = apositiveint // 2

  seen = set([x])

  while x * x != apositiveint:

    x = (x + (apositiveint // x)) // 2

    if x in seen: return False

    seen.add(x)

  return True

for i in range(110, 130):

   print i, is_square(i)

 If you are newbie and want to explore more about Python, then learn python from the below video tutorial:

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 7, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
+1 vote
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...