I am making a program in python, and Return is not working

Asked

Viewed 41 times

-2

def primo(b, d):
    d = 0
    c = 1
    x = 0
    while c < b+1:
        if b % c == 0:
            x += 1
        c +=1
    if x == 2:
        d = 1
    return d

d = 0
c = []
b = 3
a = int(input ("coloque o número que você quer que seja 'fatorado': "))
while a > 1:
    d = 0
    if a % 2 == 0:
        a = a / 2
        int(a)
        c.append("2x")
        print (a)
    else:
        primo(b, d)
        if d == 1:
            print (d)
            c.append(b, "x")
            a = a /b
            b = 3
        else:
            b +=1

print (c)
  • 1

    primo(b, d) should not be assigned to some variable?

1 answer

1

His method primo(b, d) returns the value "d", but when you call the method it is not storing this return anywhere. To solve this problem, assign the function to a variable, for example:

variavel_retorno = primo(b, d)

If you want to find out if the method is working put one print(variavel_retorno) right after calling the method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.