Answers for "How can i restrict letters after a number in an input in Python"

0

How can i restrict letters after a number in an input in Python

#Try this:

def input_string():
    x = input('str here: ')
    if 2 <= len(x) <= 6:
        number = False
        for i in range(len(x)):
            if i < 2:
                if not x[i].isupper():
                    return False
            else:
                if not number and x[i] in [str(a) for a in range(10)]:
                    number = True
                elif number:
                    if x[i] not in [str(a) for a in range(10)]:
                        return False
        return True
    return False
Posted by: Guest on May-08-2022

Code answers related to "How can i restrict letters after a number in an input in Python"

Python Answers by Framework

Browse Popular Code Answers by Language