Move History

Fork Selected
  • Description

    Just converting the int into string, reversing it by ( [::-1] ) and finaly converting again to an int.

    Code
    def reverse_int(num):
        return int(str(num)[::-1])
    Test Cases
    import codewars_test as test
    # TODO Write tests
    import solution # or from solution import example
    
    # test.assert_equals(actual, expected, [optional] message)
    @test.describe("Example")
    def test_group():
        # Why do so many people not put Python testcases into this nice format?
        @test.it("test case")
        def test_case():
            test.assert_equals(reverse_int(12345), 54321)
            test.assert_equals(reverse_int(0), 0)
  • Code
    • def reverse_int(int_reverse: int) -> int:
    • div_mod: (int, int) = divmod(int_reverse, 10)
    • reverse_int: int = div_mod[1]
    • while div_mod[0]:
    • div_mod = divmod(div_mod[0], 10)
    • reverse_int *= 10
    • reverse_int += div_mod[1]
    • return reverse_int
    • def reverse_int(num):
    • return int(str(num)[::-1])