I have a question, I am doing an exercise where you insert a number in the function and it returns True
if it is divisible by 13 and False
if it is not, but there is after doing this formula that in principle is fine:
def divide_entre_13(x):
restos = ([0, 13, 26, 39, 52, 65, 78, 91])
while x > 91:
x = abs(m.floor(x/10)-x%10*9)
if x in restos:
return True
It does not return any value or any error. In theory it should return the logical value of True
o False
but nothing. the operations are correct, I have to do it this way but there must be some syntax error somewhere or something, I don't understand.
The function currently returns
True
orNone
, it never returnsFalse
.Every function/method in Python returns
None
by default , that is, if noreturn
explicit is executed, the function returnsNone
.You have two situations where your function ends up returning
None
:if
once thewhile
) is exhausted.These two situations must be corrected, for example:
Obviously, in "normal" situations the simplest and most efficient thing to do is to do: