MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / perfect_square

Function perfect_square

maths/perfect_square.py:4–21  ·  view source on GitHub ↗

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

(num: int)

Source from the content-addressed store, hash-verified

2
3
4def perfect_square(num: int) -> bool:
5 """
6 Check if a number is perfect square number or not
7 :param num: the number to be checked
8 :return: True if number is square number, otherwise False
9
10 >>> perfect_square(9)
11 True
12 >>> perfect_square(16)
13 True
14 >>> perfect_square(1)
15 True
16 >>> perfect_square(0)
17 True
18 >>> perfect_square(10)
19 False
20 """
21 return math.sqrt(num) * math.sqrt(num) == num
22
23
24def perfect_square_binary_search(n: int) -> bool:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected