0

Security challenge

I'm removing all "x" and trying to compare "T" and "

quot; 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("
quot;) if abs (t-m) ==1: print ("ALARM") else: print ("quiet")

22nd May 2020, 8:38 AM
effy
12 Antworten
+ 3
floor = floor.replace('x', '')
22nd May 2020, 9:39 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
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
22nd May 2020, 9:06 AM
Mayank
Mayank - avatar
+ 3
floor = input() floor=floor.replace("x","") t = floor.index("T") m = floor.index("
quot;) if abs (t-m) ==1: print ("ALARM") else: print ("quiet")
13th Jan 2021, 4:18 AM
P. S
P. S - avatar
+ 2
There can be more than 1 of each and index will return the first found index of the element. Try checking if 'T
#x27; or '$T' exists in floor
22nd May 2020, 9:08 AM
ChaoticDawg
ChaoticDawg - avatar
22nd May 2020, 8:59 AM
effy
+ 1
ChaoticDawg Strange... I did this and result is the same. floor = input() floor.replace("x","") if "T
quot; in floor or "$T" in floor: print ("ALARM") else: print("quiet")
22nd May 2020, 9:35 AM
effy
+ 1
Unless you had something like; floor = input().replace('x', '') before, then it must have been coincidental.
22nd May 2020, 2:38 PM
ChaoticDawg
ChaoticDawg - avatar
12th Jun 2020, 7:26 PM
Shubhank Gupta
Shubhank Gupta - avatar
+ 1
x = ''.join(input().split('x')) y = ''.join(x.split('T
#x27;)) z = ''.join(y.split('$T')) print('ALARM'if '
#x27; not in z else 'quiet') My noob way. Passes all tests. x var removes space. y & z var remove the thiefs with money. If money is gone - prints alarm else - quiet
15th Dec 2021, 2:41 PM
Stephen Norton
Stephen Norton - avatar
0
ChaoticDawg Thanks, it works! But I don't understand why I didn't have to do it with other cases
22nd May 2020, 12:17 PM
effy
0
I believe this should be helpful: https://code.sololearn.com/cePhdduV4vuF/?ref=app
6th May 2022, 8:26 AM
Ashkan Shakibi
Ashkan Shakibi - avatar
0
https://code.sololearn.com/c2541CZp5OY8/?ref=app
13th Sep 2022, 12:03 PM
Joe Davies
Joe Davies - avatar