Security challenge | Sololearn: Learn to code for FREE!

0

Security challenge

I'm removing all "x" and trying to compare "T" and "$" positions if they are next to each other. It looks OK for me but test#4 is always failed. I know there are another ways but where is my problem? floor = input() floor.replace("x","") t = floor.index("T") m = floor.index("$") if abs (t-m) ==1: print ("ALARM") else: print ("quiet")

5/22/2020 8:38:04 AM

effy

10 Answers

New Answer

+3

floor = floor.replace('x', '')

+3

your code seems fine if there are just single instances of money, guard and thief as index will return only the first index, but as in some test cases there are multiple guards, so if there are multiple thieves or money your code might fail, and we cant verify that since test case 4 is hidden. I'd suggest use a simple for loop and build your code around that

+2

floor = input() floor=floor.replace("x","") t = floor.index("T") m = floor.index("$") if abs (t-m) ==1: print ("ALARM") else: print ("quiet")

+1

https://www.sololearn.com/coach/77?ref=app

+1

There can be more than 1 of each and index will return the first found index of the element. Try checking if 'T$' or '$T' exists in floor

+1

Unless you had something like; floor = input().replace('x', '') before, then it must have been coincidental.

+1

Easy solution :- https://code.sololearn.com/cFXMaiK5p1B0/?ref=app

0

ChaoticDawg Strange... I did this and result is the same. floor = input() floor.replace("x","") if "T$" in floor or "$T" in floor: print ("ALARM") else: print("quiet")

0

ChaoticDawg Thanks, it works! But I don't understand why I didn't have to do it with other cases

0

lel = input() G = 0 T = 0 S = 0 alarm = 0 ub = 0 up = 0 ut = 0 for x in lel: ub += 1 if "G" in x: G = 1 up = ub if "T" in x: T = 1 ut = ub if "$" in x: S = 1 if G == 1 and S == 1 and T == 0: G = 0 up = 0 S = 0 if G == 1 and T == 1 and up < ut: G = 0 up = 0 if G == 1 and T == 1 and up > ut: T = 0 ut = 0 if T == 1 and S == 1 and G == 0: alarm = 1 break if alarm == 1: print("ALARM") else: print("quiet")