-
Fundamentals
Description The YouTube video that inspired this: https://www.youtube.com/watch?v=vKlVNFOHJ9I
When a number n is inputted, the function produces a number where its digits count up to n and back down to one.
Here are some examples of how the function should function.
1 --> 1 2 --> 121 3 -- > 12321
Notice how there is only one n in the integer.
For situations where n > 9, some numbers may be two digits instead of one, such as the example here:
10 --> 12345678910987654321
All numbers will be integers greater than zero.
Code def numberprint(x): accending = list(range(1, x + 1)) descending = list(range(x-1, 0, -1)) newlist = accending + descending strings = [str(integer) for integer in newlist] a_string = "".join(strings) an_integer = int(a_string) return an_integer
Preloaded Code def numberprint(x): return
Test Cases import codewars_test as test from solution import numberprint .describe("Fixed Tests") def basic_tests(): .it("Fixed tests") def fixed_tests(): test.assert_equals(numberprint(1), 1) test.assert_equals(numberprint(2), 121) test.assert_equals(numberprint(10), 12345678910987654321)
Output:
-
- 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 }}