- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy pathpronic_number.py
55 lines (48 loc) · 1.28 KB
/
pronic_number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
== Pronic Number ==
A number n is said to be a Proic number if
there exists an integer m such that n = m * (m + 1)
Examples of Proic Numbers: 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110 ...
https://en.wikipedia.org/wiki/Pronic_number
"""
# Author : Akshay Dubey (https://github.com/itsAkshayDubey)
defis_pronic(number: int) ->bool:
"""
# 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_pronic(8)
False
>>> is_pronic(30)
True
>>> is_pronic(32)
False
>>> is_pronic(2147441940)
True
>>> is_pronic(9223372033963249500)
True
>>> is_pronic(6.0)
Traceback (most recent call last):
...
TypeError: Input value of [number=6.0] must be an integer
"""
ifnotisinstance(number, int):
msg=f"Input value of [number={number}] must be an integer"
raiseTypeError(msg)
ifnumber<0ornumber%2==1:
returnFalse
number_sqrt=int(number**0.5)
returnnumber==number_sqrt* (number_sqrt+1)
if__name__=="__main__":
importdoctest
doctest.testmod()