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

Function is_pronic

maths/special_numbers/pronic_number.py:13–49  ·  view source on GitHub ↗

# doctest: +NORMALIZE_WHITESPACE This functions takes an integer number as input. returns True if the number is pronic. >>> is_pronic(-1) False >>> is_pronic(0) True >>> is_pronic(2) True >>> is_pronic(5) False >>> is_pronic(6) True >>> is_pro

(number: int)

Source from the content-addressed store, hash-verified

11
12
13def is_pronic(number: int) -> bool:
14 """
15 # doctest: +NORMALIZE_WHITESPACE
16 This functions takes an integer number as input.
17 returns True if the number is pronic.
18 >>> is_pronic(-1)
19 False
20 >>> is_pronic(0)
21 True
22 >>> is_pronic(2)
23 True
24 >>> is_pronic(5)
25 False
26 >>> is_pronic(6)
27 True
28 >>> is_pronic(8)
29 False
30 >>> is_pronic(30)
31 True
32 >>> is_pronic(32)
33 False
34 >>> is_pronic(2147441940)
35 True
36 >>> is_pronic(9223372033963249500)
37 True
38 >>> is_pronic(6.0)
39 Traceback (most recent call last):
40 ...
41 TypeError: Input value of [number=6.0] must be an integer
42 """
43 if not isinstance(number, int):
44 msg = f"Input value of [number={number}] must be an integer"
45 raise TypeError(msg)
46 if number < 0 or number % 2 == 1:
47 return False
48 number_sqrt = int(number**0.5)
49 return number == number_sqrt * (number_sqrt + 1)
50
51
52if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected