mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-23 23:19:47 +00:00
parent
8a5633a233
commit
6d44cdd315
27
maths/perfect_square.py
Normal file
27
maths/perfect_square.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
|
def perfect_square(num: int) -> bool:
|
||||||
|
"""
|
||||||
|
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()
|
Loading…
x
Reference in New Issue
Block a user