def check_input(predicate, msg, error_string='Illegal Input'):
    while True:
        result = input(msg).strip()
if predicate(result):
    return result
print(error_string)
result = check_input(lambda x: x in ['male', 'female'],
    'Are you male or female? ')
print(result)
библиотека python для пользовательского ввода