From af443c3deab7298875a146872924e47f47a788a6 Mon Sep 17 00:00:00 2001 From: echace13 <69325784+echace13@users.noreply.github.com> Date: Thu, 8 Oct 2020 23:01:54 +0530 Subject: [PATCH] Added code for perfect square added command to check if a number is a perfect square. --- app.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index daaf97e..13e47ca 100644 --- a/app.py +++ b/app.py @@ -33,7 +33,15 @@ def prime(): else: print("False") - +def perfect_square(): + n = int(input("Enter a number: ")) + x = n // 2 + y = set([x]) + while x * x != n: + x = (x + (n // x)) // 2 + if x in y: return False + y.add(x) + return True if __name__=='__main__': add()