+ 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
11 Respostas
+ 19
My code:
string = input()
situation = string.replace("x", "")
if "Tquot; in situation or "$T" in situation:
print("ALARM")
else:
print("quiet")
+ 10
Honestly that's clever KnuckleBars! I didn't think about that!
+ 9
My solution feels like cheating! I just remove all the x and then an if statement if you can find $T ot T$
+ 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
+ 1
Itâs not cheating if it works!Thatâ what I posted for...to see others workarounds and ideas!
+ 1
stripped = input().replace('x','')
print("ALARM" if "$T" in stripped or 'T#x27; in stripped else 'quiet')
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
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")
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")
- 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()
- 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])