Search code examples
pythonif-statementraw-input

Check how many characters in input


I'm working on a Python script for school and I need it to check the input format in order to perform an action.

Let me exemplify:

The script will ask the user for an input that can either be an id number or a registration number, then, if it's an ID number, it will query a specific database for something, and if it's a registration number, it will query a different database for something else.

The ID number format is: XXX.XXX.XXX-XX and the registration number format is: XX.XXX.XXX/XXXX-XX.

Any ideas?

[EDIT]

Ok, so I just realized I don't necessarily need to check if the format is correct, since the registration number has more characters than the ID number. Now, how can I have an if statement check the amount of characters in an input?


Solution

  • So I ended up using the following:

    if len(cliente) == 14:
        print "ID"
    
    
    elif len(cliente) == 18:
        print "Registration"
    
    else:
        print "You entered an incorrect option"
    

    Which worked quite well for what I needed. Thanks :D