+ 2

security challange

it get 3 right only import sys x=str(input()) T=0 G=0 z=0 T1=0 G1=0 n=len(x) S=x.index('

#x27;) try: G=x[0:S].index("G") except: print("ALARM") sys.exit() try: G1=x[S+1:n].index("G") except: print("ALARM") sys.exit() try: T=x[0:S].index("T") except: z=1 try: T1=x[S+1:n].index("T") except: z=2 if T>G: print("ALARM") elif T1<G1: print("ALARM") elif z==1 and z==2: print("quiet"),sys.exit() else: print("quiet")

26th Feb 2020, 1:28 PM
abdosamyeid
abdosamyeid - avatar
4 Réponses
+ 1
As it's a little bit hard to follow your logic, I think you're not taking into account that there may be multiple Guards. Index returns only the first occurence.
26th Feb 2020, 2:04 PM
Mihai Apostol
Mihai Apostol - avatar
+ 1
1. Firstly, try to get the index of thief and index of money from the given string. 2. Now iterate over the string from index with least value to index with highest value that you got in step 1 and search for any guard in between. If yes, then print quiet else ALARM.
26th Feb 2020, 3:45 PM
Dodla Dileep Reddy
Dodla Dileep Reddy - avatar
0
If i remember good than "alert" should be only if between thief and money haven't any guard.. So in your case you in first step check if guard isn't before money then "alert" but there also maybe haven't any Thief Example: xxxx$xxxx There's no thief but also no guard. So in x.index('G') you get exception and print "alert".
26th Feb 2020, 9:20 PM
DolphinMuks
DolphinMuks - avatar
0
Alternatively, remove the 'x' and check if the index of money + or - 1 is the thief...
28th Feb 2020, 11:02 PM
Salvatore Junior Iaccarino
Salvatore Junior Iaccarino - avatar