The expression len(password) is repeated twice in this line:
if len(password) >= 8 and len(password) <= 16:
This is simpler:
if 8 <= len(password) <= 16:
For the score comparison, you could replace the if/elif with a match/case statement.
That would eliminate repeating the score == code.
UX
It would be nice to give the user a chance to break out of the loop cleanly, without using Ctrl-c to terminate the program.
It would also be good to set a limit on the number of tries.
It is good that you inform the user of the expected password length, but you should also
display the other criteria for a strong password:
- Letter
- Number
- Special character
When the user chooses a weak or medium password, you could also display the reasons why it is so.
Input checking
It is great that you check that the input is within your required range. Consider using pyinputplus for more
options on input checking.
Your checker allows spaces. For example, this was accepted:
123456 78
If that is not intentional, then you should add a check for that situation.
Typo
The function name pass_strenght has a typo. It should be "strength":
def pass_strength(password):
Documentation
The PEP 8 style guide recommends
adding docstrings for functions. For example:
def pass_strenght(password):
"""
Determine the strength of a password
The input is the password string.
The returned value is one of these strings: weak, medium, strong
"""
Also consider using type hints
to describe input and return types of the functions to make the code even more self-documenting.
Naming
The function name main is too generic. You could give it a more meaningful name like
get_and_print_password. Or, you could just eliminate it completely. It is great that
you added a "main" guard, and instead of:
def main():
password = pass_input()
print(pass_strenght(password))
if __name__ == "__main__":
main()
you could use:
if __name__ == "__main__":
password = pass_input()
print(pass_strenght(password))
This can be further simplified as:
if __name__ == "__main__":
print(pass_strenght(pass_input()))
The variable name digit implies that it is a number. Perhaps the name character is more appropriate.