Prompt the user to input something else if the first input is invalid [duplicate]

To go on with the next loop iteration, you can use the continue statement.

I’d usually factor out the input to a dedicated function:

def get_input(prompt):
    while True:
        s = raw_input(prompt)
        if len(s) == 10 and set(s).issubset("abcdef"):
            return s
        print("The only valid inputs are 10-character "
              "strings containing letters a-f.")

Leave a Comment