mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-07 03:07:46 +08:00
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort * Fixed doctest error due whitespace * reduce loop times for optimization * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -4,28 +4,28 @@
|
||||
def decimal_to_binary(num: int) -> str:
|
||||
|
||||
"""
|
||||
Convert an Integer Decimal Number to a Binary Number as str.
|
||||
>>> decimal_to_binary(0)
|
||||
'0b0'
|
||||
>>> decimal_to_binary(2)
|
||||
'0b10'
|
||||
>>> decimal_to_binary(7)
|
||||
'0b111'
|
||||
>>> decimal_to_binary(35)
|
||||
'0b100011'
|
||||
>>> # negatives work too
|
||||
>>> decimal_to_binary(-2)
|
||||
'-0b10'
|
||||
>>> # other floats will error
|
||||
>>> decimal_to_binary(16.16) # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: 'float' object cannot be interpreted as an integer
|
||||
>>> # strings will error as well
|
||||
>>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: 'str' object cannot be interpreted as an integer
|
||||
Convert an Integer Decimal Number to a Binary Number as str.
|
||||
>>> decimal_to_binary(0)
|
||||
'0b0'
|
||||
>>> decimal_to_binary(2)
|
||||
'0b10'
|
||||
>>> decimal_to_binary(7)
|
||||
'0b111'
|
||||
>>> decimal_to_binary(35)
|
||||
'0b100011'
|
||||
>>> # negatives work too
|
||||
>>> decimal_to_binary(-2)
|
||||
'-0b10'
|
||||
>>> # other floats will error
|
||||
>>> decimal_to_binary(16.16) # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: 'float' object cannot be interpreted as an integer
|
||||
>>> # strings will error as well
|
||||
>>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: 'str' object cannot be interpreted as an integer
|
||||
"""
|
||||
|
||||
if type(num) == float:
|
||||
|
Reference in New Issue
Block a user