Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Reverse Integer by Khrystyna11
def reverse_digits(num: int) -> int:
# your code here
if num < 0:
multiplier = -1
else:
multiplier = 1
num *= multiplier
reserved_str = str(num)[::-1]
from_str_to_int = int(reserved_str)
return from_str_to_int * multiplier
print("Example:")
print(reverse_digits(32))
# These "asserts" are used for self-checking
assert reverse_digits(1234) == 4321
assert reverse_digits(0) == 0
assert reverse_digits(-123) == -321
assert reverse_digits(5) == 5
assert reverse_digits(-9) == -9
assert reverse_digits(100) == 1
assert reverse_digits(-100) == -1
assert reverse_digits(54321) == 12345
assert reverse_digits(1111) == 1111
assert reverse_digits(987654321) == 123456789
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 8, 2024
Comments: