Why i am sticking here ? This is the casino problem, hard | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why i am sticking here ? This is the casino problem, hard

string = input( ) if "

quot; in string or "T" in string or "G" in string or "x" in string : if "
quot; not in string : print("quiet") elif "T" not in string : print("quiet") elif "G" not in string and "
quot; in string and "T" in string : print("ALARM") elif "
quot; not in string and "T" not in string and "G" not in string : print("quiet") if "
quot; in string and "T" in string and "G" in string : money_flor = string.index("
quot;) thif_flor = string.index("T") guard_flor = string.index("G") k = [ ] m = 0 for i in string : if i in k : guard_flor = m k.append(i) m += 1 for i in string : if i == "G" and string.index(i)>money_flor : guard_flor = string.index(i) if money_flor < guard_flor and guard_flor < thif_flor : print("quiet") elif money_flor > guard_flor and guard_flor > thif_flor : print("quiet") else : print("ALARM")

8th Jul 2021, 12:28 PM
UnTentetive
9 Answers
+ 1
Amit Ranjan Sahoo good job! But... The problem tells you: Input: string containing one "
quot;, one "T", some "G" and some "x" You need to print("quiet") if there is a G is in beetwen $ and T else print("ALARM") I challenge you to rewrite the sentence above in python in less than, let's be generous, 15 (readable) lines If you have time, try doing it
8th Jul 2021, 3:00 PM
Angelo
Angelo - avatar
+ 5
Amit Ranjan Sahoo , i would suggest that you re-start a try with input() and getting the index from "G", "
quot; and "T". (as you already have done) with the 3 different elements we have, we could create 6 unique possible samples. but only 2 of them can give "quiet". "quiet" is only possible, when "G" is in the MIDDLE of the others. so these two are: $GT and TG$. these 2 are easy to check by the index you have already stored. for these 2 output "quiet", and for all the others output "ALARM" happy coding and good success!
8th Jul 2021, 2:26 PM
Lothar
Lothar - avatar
+ 5
Doug Warner , your post has no relation to the topic of this feed. this can be seen as spam. > maybe you wanted to modify your post. > otherwise it would be better if you start your own question, because the current discussion started one year ago. people may not be aware of your issue.
20th Apr 2023, 10:05 AM
Lothar
Lothar - avatar
+ 2
Come on! This should be python, you can even do it in less than 7 lines! I know you can do it! I'll give you a hint: Take the substring from $ to T (you don't need to check if they're in string, the problem says they'll be there)
8th Jul 2021, 1:16 PM
Angelo
Angelo - avatar
+ 2
You do that so good. I challenge you to solve this problem with more $ and T , print "Alarm" if there is at least 1 $ between T and G else print "quiet"
9th Jul 2021, 9:53 AM
TCorn
TCorn - avatar
+ 1
Angelo I did it but can't in 15 line but in 19 line of code 😀👍. Thank you for your challenge. I find the bug and did it in short❤️. Here it is 👇👇👇 string = input() m = 0 k = [ ] if "G" in string : gp = string.index("G") for i in string : if i in k : gp = m if i == "G" : k.append(i) m += 1 if gp < string.index("
quot;) and gp > string.index("T") : print("quiet") elif gp>string.index("
quot;) and gp<string.index("T") : print("quiet") else : print("ALARM") else : print("ALARM")
9th Jul 2021, 4:36 AM
UnTentetive
0
Angelo Bro yes,i found it in delay 😂,but i found 👍. Thnks for answering.
8th Jul 2021, 2:17 PM
UnTentetive
0
Great!
8th Jul 2021, 2:17 PM
Angelo
Angelo - avatar
0
Lothar I solved 👇 #number of floors string = input( ) #here thif is one and place where the money is one. #but number of guards are different, there can be one thif between two guards ! if "
quot;not in string or "T"not in string or "G" not in string or "x"not in string : if "G" in string and "
quot; in string and "T"not in string : print("quiet") if "
quot; not in string : print("ALARM") elif "G" not in string and "
quot; in string and "T" in string and "x"in string : print("ALARM") if "
quot; in string and "T" not in string and "G"not in string and "x" not in string : print("ALARM") if "
quot; in string and "T" in string and "G" in string : money_flor = string.index("
quot;) thif_flor = string.index("T") guard_flor = string.index("G") k = [ ] m = 0 for i in string : if i in k and "T" not in k : guard_flor = m k.append(i) m += 1 for i in string : if i == "G" and string.index(i)>money_flor : guard_flor = string.index(i) if money_flor < guard_flor and guard_flor < thif_flor :
8th Jul 2021, 2:30 PM
UnTentetive