From e16a621b014436270d45c5f5298bad33001f0f95 Mon Sep 17 00:00:00 2001 From: shellhub Date: Thu, 31 Oct 2019 18:30:25 +0800 Subject: [PATCH 1/2] perfect square --- maths/perfect_square.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 maths/perfect_square.py diff --git a/maths/perfect_square.py b/maths/perfect_square.py new file mode 100644 index 000000000000..07af0c1202a1 --- /dev/null +++ b/maths/perfect_square.py @@ -0,0 +1,27 @@ +import math + + +def perfect_square(num): + """ + Check if a number is perfect square number or not + :param num: the number to be checked + :return: True if number is square number, otherwise False + + >>> perfect_square(9) + True + >>> perfect_square(16) + True + >>> perfect_square(1) + True + >>> perfect_square(0) + True + >>> perfect_square(10) + False + """ + return math.sqrt(num) * math.sqrt(num) == num + + +if __name__ == '__main__': + import doctest + + doctest.testmod() From 33d3d2e02ee1f67dc925978a234b452c8653be84 Mon Sep 17 00:00:00 2001 From: shellhub Date: Thu, 31 Oct 2019 19:26:11 +0800 Subject: [PATCH 2/2] perfect square --- maths/perfect_square.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/perfect_square.py b/maths/perfect_square.py index 07af0c1202a1..9b868c5de98a 100644 --- a/maths/perfect_square.py +++ b/maths/perfect_square.py @@ -1,7 +1,7 @@ import math -def perfect_square(num): +def perfect_square(num: int) -> bool: """ Check if a number is perfect square number or not :param num: the number to be checked