I
I
i_ikigai2020-06-03 23:41:55
Python
i_ikigai, 2020-06-03 23:41:55

How to recurse a given number from left to right?

Given a natural number N. Print all its digits one at a time, in the usual
order, separating them with spaces or newlines. When solving this
problem, you cannot use strings, lists, arrays (well, and cycles, of
course). Only recursion and integer arithmetic are allowed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-06-04
@i_ikigai

def p(k):
  if k < 10:
    return str(k)
  else:
    return p(k//10) + str(k%10)

p(142857)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question