(Python3) If check that should be False returning True


#1

This is the code in question:

def find_next(pos):
    for gate in gateway:
        for i in links:
            if (pos, gate) == i or (gate, pos) == i:
                links.pop(links.index(i))
                return f"{pos} {gate}"
    return 0           


while True:
    si = int(input()) 

    if find_next(si) != 0:
        print(find_next(si))
    else:
        print("0 9")

Basicaly i’m trying to find the the next position, if i can’t find it in the find_next() function it should return 0.
Latter in the code i’m checking if the find_next() function return 0 or not, if it doesn’t return 0 I whant to print it, if it does return 0 i whant to print “0 9”.

But for some reason it is printing 0, what shoudn’t happen, because if find_next() is 0 it should print “0 9” instead of itself.

Tried the same code on PyCharm, it worked fine.

this is the challenge i’m facing this issue
this is my code in case you wanna try to reproduce


#2

You call the function twice.
On the first call (to check if there is a link) you return a non-0 value and remove the link.
On the second call used to print your answer, you don’t have that link anymore.


#3

Thansk for the reply.
But how can in the first call return a non zero value and in the second one it does if i runned the function using exactly the same paramenters.
And if it was true in pycharm i should face the same issue wich doesn’t happen.


#4

I was able to solve calling the function only once, thank you for your help