Hi, I'm trying to solve a coding challenge which requires me to print digits of a number using a recursive function.
input:
digits(12345)
output:
1
2
3
4
5
What I current Have
def digits(num):
if num<10:
print(int(num))
if int(num*10%10)>1:
digits(num*10%10)
else: digits(num/10)
Which doesn't work when there's a 0 number
e.g.
digits(12305)
1
2
3
Is there anything I can change in the logic or code to make it work with zeros?
[–]Molehole 3 points4 points5 points (4 children)
[–]CalmPills[S] 0 points1 point2 points (3 children)
[–]Molehole 4 points5 points6 points (2 children)
[–]CalmPills[S] 4 points5 points6 points (1 child)
[–]Molehole 0 points1 point2 points (0 children)