0
Can you make this shorter ?(help me pls)
9 Respostas
+ 5
visph, this an exercise from codecoach called "security"
Lành Nguyễn ,
what you have to do is check for 2 general patterns:
▪︎$x..xT
▪︎Tx..x$
but there for you have to remove all "x" from the string or replace them by an empty string ""
now you only have to check if these pattern occures in the input string by using the membership operator :
▪︎$T
▪︎T$
if one of these patterns is in the string -> ALARM, otherwise -> quiet
+ 2
The original Code Coach problem has only one "quot; in the input string. Are you challenging yourself to extend the problem with more than one "quot;?
+ 1
what's the purpose of your code?
what's expected as input?
+ 1
Would this be short enough for you? You only need to compare their relative positions in the input string.
n = input()
s = n.find("quot;)
t = n.find("G")
k = n.find("T")
while t >= 0:
if (s<t<k) or (s>t>k):
ans = "quiet"
break
t = n.find("G", t + 1)
else:
ans = "ALARM"
print(ans);
+ 1
Lành Nguyễn what Lothar suggest is to use "regular expression" pattern ;)
+ 1
Lothar :D
my bad: word 'pattern' and use of $ make me guess that by reading too fast and having in head the possibility to use regexp ^^
+ 1
Brian . But when I run your code I write "xxGx$xGxTxx$xx" when run it print"quiet" while between T and $ has no Guard
0
I took a note of it on the top(my English is bad ,forgive me)