+ 1
Security challenge (code coach)
Hi guys, look at my ugly code.... How can I do it more readable and smaller? https://code.sololearn.com/cUa9nCqx53Wg/?ref=app
8 Réponses
+ 9
N/A ,
i did a try with a different approach:
> input: `xxxxxGxx$xxxT` , now remove all `x`, results in: `G$T`
> now we can check if `$T` or `T
is in the reduced string.
> if True => `ALARM`
> else => `quiet`
https://code.sololearn.com/c07up5UHY9FI/?ref=app
+ 7
Dragon RB ,
you may check for the input sequence 'xxxxxGxxTxxx#x27; . in the current code the result will be *quiet*, but should be *ALARM*.
+ 4
Maybe break it up into a custom function or two? I.just looked at my solution and I created one function .
https://code.sololearn.com/cfivpG6gnI8W/?ref=app
+ 3
Another way of solving this code coach is to use the re library. The re library is for regular expressions, where it is used for things like finding a word that matches the given pattern, which is quite useful. Besides, it is easy to use, and its performance is really good.
https://code.sololearn.com/cwDbBd95ChW6/?ref=app
+ 2
Task:
Evaluate a given floor of the casino to determine if there is a guard between the money and the thief, if there is not, you will sound an alarm.
Input Format:
A string of characters that includes $ (money), T (thief), and G (guard), that represents the layout of the casino floor.
Space on the casino floor that is not occupied by either money, the thief, or a guard is represented by the character x.
Output Format:
A string that says 'ALARM' if the money is in danger or 'quiet' if the money is safe.
Sample Input:
xxxxxGxx$xxxT
Sample Output:
ALARM
+ 2
Thank you guys! Got it
+ 1
Lothar Oh thank you! This program was made using regex, but I wonder why when I put all "ALARM" posibilities on the pattern, one(or some) of them does not work as expected.
+ 1
str=input()
str=str.replace('x','')
e=str.find('T#x27;)
if(e==-1):
print('quiet')
else:
print('ALARM')