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")12 Respostas
+ 3
floor = floor.replace('x', '')
+ 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
+ 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")
+ 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
+ 1
ChaoticDawg
Strange... I did this and result is the same.
floor = input()
floor.replace("x","")
if "Tquot; in floor or "$T" in floor:
print ("ALARM")
else:
print("quiet")
+ 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
+ 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
0
ChaoticDawg
Thanks, it works! But I don't understand why I didn't have to do it with other cases
0
I believe this should be helpful:
https://code.sololearn.com/cePhdduV4vuF/?ref=app
0
https://code.sololearn.com/c2541CZp5OY8/?ref=app