Skip to content

Commit 8df841f

Browse files
committed
improve more function
1 parent 1519ff8 commit 8df841f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

maths/special_numbers/hamming_numbers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def hamming(n_element: int) -> list:
1313
:param n_element: The number of elements on the list
1414
:return: The nth element of the list
1515
16+
>>> hamming(-5)
17+
Traceback (most recent call last):
18+
...
19+
ValueError: a should be a positive number
1620
>>> hamming(5)
1721
[1, 2, 3, 4, 5]
1822
>>> hamming(10)

maths/special_numbers/harshad_numbers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def int_to_base(number: int, base: int) -> str:
1111
Where 'base' ranges from 2 to 36.
1212
1313
Examples:
14+
>>> int_to_base(0, 21)
15+
'0'
1416
>>> int_to_base(23, 2)
1517
'10111'
1618
>>> int_to_base(58, 5)
@@ -26,6 +28,10 @@ def int_to_base(number: int, base: int) -> str:
2628
Traceback (most recent call last):
2729
...
2830
ValueError: 'base' must be between 2 and 36 inclusive
31+
>>> int_to_base(-99, 16)
32+
Traceback (most recent call last):
33+
...
34+
ValueError: number must be a positive integer
2935
"""
3036

3137
if base < 2 or base > 36:
@@ -101,6 +107,8 @@ def harshad_numbers_in_base(limit: int, base: int) -> list[str]:
101107
Traceback (most recent call last):
102108
...
103109
ValueError: 'base' must be between 2 and 36 inclusive
110+
>>> harshad_numbers_in_base(-12, 6)
111+
[]
104112
"""
105113

106114
if base < 2 or base > 36:

0 commit comments

Comments
 (0)