Adding the function isProthNumber(n : int) which returns true if n is a Proth number

This commit is contained in:
Juanitoupipou 2024-11-27 15:49:52 +01:00
parent 6e24935f88
commit 5f54615b8b

View File

@ -59,6 +59,38 @@ def proth(number: int) -> int:
return proth_list[number - 1]
def isProthNumber(number: int) -> bool :
"""
:param number: nth number to calculate in the sequence
:return: true if number is a Proth number, false etherwise
>>> proth(5)
true
>>> proth(34)
false
>>> proth(-1)
Traceback (most recent call last):
...
ValueError: Input value of [number=-1] must be > 0
>>> proth(6.0)
Traceback (most recent call last):
...
TypeError: Input value of [number=6.0] must be an integer
"""
if number < 1:
msg = f"Input value of [number={number}] must be > 0"
raise ValueError(msg)
N = number
N -= 1
n = 0
while N%2 == 0 :
N = N/2
n += 1
return N < (2**n)
if __name__ == "__main__":
import doctest
@ -73,3 +105,11 @@ if __name__ == "__main__":
continue
print(f"The {number}th Proth number: {value}")
list = [3, 5, 9, 13, 49, 57, 193, 241, 163, 201]
for number in list :
if isProthNumber(number):
print(f"{number} is a Proth number")
else :
print(f"{number} is not a Proth number")