So i have this code:
x = 1
while x <= 2:
text = input("> ")
to_deny = "!?/"
find=["find subsystem"]
if any(char in text for char in to_deny):
print("text contains restricted characters")
quit()
if any(char in text for char in find):
print(f"finding subsystem: {text}")
if text == "quit":
quit()
elif text == "clear":
import os
os.system("clear")
else:
print(f"running {text}....")
And i want to make it so when you say " find subsystem" (cringe, i know) it will instead print "finding subsystem: (name of subsystem goes here)" and not "finding subsystem: (subsystem) running (subsystem)…."
I have tried everything i could possibly think of but my stupid 2 brain cell mind only tried:
Using lists (i forgot how to make one :/)
Using a dictionary (forgot how to make one too)
>Solution :
Put all the mutually exclusive operations that don’t result in a break or continue in a single if...elif...else chain so that you don’t "fall through" from one into the next.
import os
to_deny = "!?/"
find = "find subsystem "
while True:
text = input("> ")
if any(char in text for char in to_deny):
print("text contains restricted characters")
break
if text == "quit":
break
if find in text:
text = text.replace(find, "")
print(f"finding subsystem: {text}")
elif text == "clear":
os.system("clear")
else:
print(f"running {text}....")
> find subsystem abc
finding subsystem: abc
> blargh
running blargh....
>