+ 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

13th Aug 2023, 9:28 AM
N/A
8 Answers
+ 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
13th Aug 2023, 3:10 PM
Lothar
Lothar - avatar
+ 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*.
13th Aug 2023, 7:04 PM
Lothar
Lothar - avatar
+ 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
13th Aug 2023, 10:37 AM
Keith
Keith - avatar
+ 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
13th Aug 2023, 5:07 PM
Dragon RB
Dragon RB - avatar
+ 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
13th Aug 2023, 9:29 AM
N/A
+ 2
Thank you guys! Got it
14th Aug 2023, 6:44 PM
N/A
+ 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.
14th Aug 2023, 2:00 AM
Dragon RB
Dragon RB - avatar
+ 1
str=input() str=str.replace('x','') e=str.find('T
#x27;) if(e==-1): print('quiet') else: print('ALARM')
14th Aug 2023, 7:46 AM
Jakku Shashank
Jakku Shashank - avatar