-4

understandable versions of Question:

  • How to detect and get strings inside of parenthesis?
  • How to detect and get datatypes inside of parenthesis?
  • How to detect and get strings inside of parenthesis using If?
  • How to detect and get datatypes inside of parenthesis using if?

example:

x = input("send command(only allow 1 digits of character and only allow A,B<C<D<E<and F)")
if x == "$C A":
    print(x)
elif x == "$C B":
    print(x)
...

6 possibilities(if and elif statements)

tried: using rfind method, rpartition method translate method(translate from parenthesis to curly brackets), used format() method, used str() function

my code(with if statements):

def commandLine():
    c = input()
    if c = "$CR -f a"
        print("you made a file named a")
    elif c = "$CR -f A"
        print("you made a file named A")
...

possibilites: 15,000 or 7,000

lazy code:

def commandLine():
    c = input()
    if c = "$CR -f"
        f = input("filename: ")
        print(f)

possibilites with short code: Infinity(infinite characters can be typed in the f=input() variable)

1 Answers1

0

You can split your input and make if/else statement with every parameter:

def commandLine():
    c = input()
    c = c.split(" ")
    if c[0] == "$CR":
      if c[1] == "-f":
        if c[2]:
          print("you made a file named {}".format(c[2]))
commandLine()

I'm not sure if this is what you were asking but it's what i understood. I hope it helps

Output:

$CR -f A
you made a file named A
Rayken
  • 121
  • 4
  • i have a problem. so when i made a command that writes inside files, it only wrote the "hello," instead of "hello, world" – imdumb.com Apr 21 '23 at 23:27
  • It this text is at the end of the command line you can use something like this: `" ".join(c[2:])` it will get all the text from the number of command that you put to the end of your command line – Rayken Apr 22 '23 at 00:47
  • where do i put it? – imdumb.com Apr 22 '23 at 12:44
  • in this example if you want a multi word name you should put it like this: `print("you made a file named {}".format(" ".join(c[2:])))` i can´t really tell you where to put it whitout looking at your code, but i think this example could help you – Rayken Apr 23 '23 at 21:55