0

I want to check a specific part of an input but I don't know "where" it is

I tried with this: a = input('Enter command')

if a[0:5] == '(Command name)':

    if a[7:?] == '(Subject)':

        if a[?:len(a)] == '(Choice)':

            To be continued

So, the input is divided into three parts; The command, the subject, and which type of the command it will run. But which index should the ? be? I don't know the length of the word. Is it impossible?

No, I know that I can make it, just not how.

2 Answers2

0

If they are always one word, maybe something like this will work:

terms = a.strip().split(" ")
command_name = terms[0]
subject = terms[1]
choice = terms[2]

if there is a possibility of double spaces, it needs to be more clever


the above is the same as

command_name, subject, choice = a.strip().split(" ")
Alex028502
  • 3,486
  • 2
  • 23
  • 50
0

I suppose your input should go something like this:

command subject choice

So there are basically three parts(might be more). I suggest you break the input in list as:

a = [str(x) for x in input().split()]

To get the length of each entities:

len(entity)

And for index you can use index():

list.index(entity)
Kumar Aditya
  • 39
  • 1
  • 2