elif not password[i].isdigit():
digit += 1
That is a good start to count the digits. But it is not used to return True or False.
Do a similar thing with special:
elif password[i] in special_char:
special += 1
At the end of the function, you could do:
val = val and digit > 2 and special > 2
before returning val (without the if).
However, I think you will also need to debug the code, as there might be a ‘not’ too much.
CLICK HERE to find out more related problems solutions.