+ 4

Security Code Coach Problem in Python

I have just started to learn Python and am finding it a lot easier than Java to just pick up and run with. Here’s my first Code Coach solution - which seemed a lot easier than the Hard rating it was given! Is there anything I could do to make it simpler still? Or to use better practice? Thanks! https://code.sololearn.com/cZD4VQ6we4sn/?ref=app

8th Feb 2020, 11:41 PM
Neil Walker
Neil Walker - avatar
11 Antworten
+ 19
My code: string = input() situation = string.replace("x", "") if "T
quot; in situation or "$T" in situation: print("ALARM") else: print("quiet")
9th Feb 2020, 1:03 AM
KnuckleBars
KnuckleBars - avatar
+ 10
Honestly that's clever KnuckleBars! I didn't think about that!
9th Feb 2020, 1:07 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 9
My solution feels like cheating! I just remove all the x and then an if statement if you can find $T ot T$
9th Feb 2020, 1:02 AM
KnuckleBars
KnuckleBars - avatar
+ 3
Check out 👇 s=input() a=0 for i in range(len(s)-1): if s[i] =='
#x27;or s[i]=='T': for j in range(i+1,len(s)): if s[j]=='G': a=1 break elif s[j]=='T' or s[j]=='
#x27;: a=2 break if a==1: print ("quiet") break elif a==2: print("ALARM") break
23rd Jul 2021, 3:18 PM
Tharul Nejana
Tharul Nejana - avatar
+ 1
It’s not cheating if it works!That’ what I posted for...to see others workarounds and ideas!
9th Feb 2020, 7:52 AM
Neil Walker
Neil Walker - avatar
+ 1
stripped = input().replace('x','') print("ALARM" if "$T" in stripped or 'T
#x27; in stripped else 'quiet')
14th Dec 2021, 2:39 PM
Mateo González Bufi
Mateo González Bufi - avatar
0
This is how I made mine simple if you're interested: 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') Noob style: passes all tests. #x removes space. #y&z remove only the thieves with money #If money is gone an alarm #else - it's all quiet
15th Dec 2021, 3:09 PM
Stephen Norton
Stephen Norton - avatar
0
inp = input() a_list = list(inp) x =[i for i,d in enumerate(a_list) if d=='G'] G = x[-1] S = a_list.index("
quot;) y =[i for i,d in enumerate(a_list) if d== 'T'] T = y[0] if G < S < T or G > S > T: print("ALARM") elif S > G > T or S < G < T: print("quiet")
24th Jan 2022, 9:01 PM
Snir Azulay
0
import re entry = input() diagram = re.sub("[x]", "" ,entry) if "G$T" in diagram or "T$G" in diagram: print("ALARM") else: print("quiet")
6th Sep 2022, 9:10 PM
yonis Alvarez
yonis Alvarez - avatar
- 1
import re def floorvalidate(floor): pattern1 = r"Tx*\
quot; pattern2 = r"\$x*T" thief_money = re.search(pattern1, floor) money_thief = re.search(pattern2, floor) if thief_money or money_thief: return "ALARM" else: return "quiet" floor_layout = input()
3rd Aug 2021, 5:13 AM
TrebleClef20
TrebleClef20 - avatar
- 2
outcomes = dict( G = { "G": "hello friend!", "S": "wish I'd had this money", "T": "go away thief!" }, S = { "G": "move along", "T": "fu.. he's gonna take me" }, T = { "G": "fu.. the guards!", "S": "payday" } ) value = input().replace("x", "").replace("
quot;, "S") value += "G" + value[::-1] cases = [] for cur,upcoming in zip(value[:-1], value[1:]): outcome = outcomes[cur][upcoming] cases.append(outcome) res = { 1: "ALARM", 0: "quiet" } switch = 0 if "payday" in cases or "fu.. he's gonna take me" in cases: switch = 1 print(res[switch])
20th Feb 2020, 11:27 PM
Ana Adrian
Ana Adrian - avatar