[Python] Why doesnt the called function pick up the loop range variable? [closed]

Discussão em 'Python' iniciado por Stack, Julho 9, 2025.

  1. Stack

    Stack Membro Participativo

    Instead of getting binary numbers conversions of integers, I get 'none' as the output.

    def dec_to_bin(n):
    if n > 1: # recursively divide the number
    dec_to_bin(n // 2)
    global res
    res += str(n % 2) # append the remainder (binary digit)

    n = 17
    print(n)
    res = ''
    print("dec_to_bin(17)=",dec_to_bin(17) )

    for i in range(1, 10):
    x = dec_to_bin(i)
    print(i,": ",x)

    Continue reading...

Compartilhe esta Página