Security problem in Python.
Hey guys, I was trying to solve this question but seems like the compiler reads my code in wrong way. I think I've done right. Out of 5 tests it qualifies in 4 only fails the first test which I think it shouldn't as I checked it. Here is the question: https://www.sololearn.com/coach/77?ref=app Pls let me know what in my code is wrong. Thank you. And here is the code that I wrote: floor=input() count=0 for i in range(len(floor)): if floor[i]=='x': continue elif floor[i]=='$' or floor[i]=='T': if count==1: print('ALARM') break else: count+=1 elif floor[i]=='G': if count==1: print('quiet') break else: print('ALARM') break else: break
5/27/2021 12:58:27 PM
Prakhar
11 Answers
New Answerx = ''.join(input().split('x')) y = ''.join(x.split('T$')) z = ''.join(y.split('$T')) print('ALARM'if '$' 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
For this input xxxxxGxx$xGxT your code deliver ALARM and this is wrong. Try to solve this.
It took me a while and I tried other way more complicated leads. But often I have to scrap those leads because it's simpler than I had originally thought. This is one of those times. I like the way it came out.
I actually just started coding 2 months ago. But for many years I taught myself math and logic and I love them both. So, it helps me a lot with the problem solving. But experienced - not even close. I don't even know how to use classes and stuff. That may even be why my code is simpler. Lol
Stephen Norton Now that the difference between my code and an experienced guy's code lmao... Thanks, I'll test this one now.
I've been away from coding stuffs for a while now but I'm trying to start Python from scratch now... Have an IT exam next year...