-
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) .describe("Example") def test_group(): # Why do so many people not put Python testcases into this nice format? .it("test case") def test_case(): test.assert_equals(reverse_int(12345), 54321) test.assert_equals(reverse_int(0), 0)
Output:
-
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 *= 10reverse_int += div_mod[1]return reverse_int- def reverse_int(num):
- return int(str(num)[::-1])
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}