1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Why is my Python recursive function returning None instead of the expected value?

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    I wrote a simple recursive function to calculate the sum of digits of a number.
    But instead of returning an integer, it prints None.

    def digit_sum(n):
    if n < 10:
    return n

    print(digit_sum(n // 10) + n % 10)

    result = digit_sum(452)
    print(result)

    Continue reading...

Compartilhe esta Página