corrwct my python code for ROBOGAME beginner problem 1

…:

t=int(input())
d=0
f=1
for i in range(t):
    s=input()
    for j in range(0,len(s)):
        if s[j].isdigit():
            d+=1
            l=j+int(s[j])
            for k in range(j+1,len(s)):
                if s[k].isdigit():
                    m=k-int(s[k])
                    if m<=l:
                        f=0
                        break
                    else:
                        f=1
    if f==1 or d==0 or d==1:
        print("safe")
    else:
        print("unsafe")

That ‘break’ only takes you out of the k-loop - the j-loop continues. So the code can process a subsequent good combination after finding an unsafe pairing and will set f to 1 again, which will show up wrongly as a safe string.

Example
…1…2…1.

(should be unsafe)