密码复杂度 编写一个函数,参数为一串明文密码字符串,返回值为字符串长度以及字符串里面的大写字母、小写字母,和数字的个数总共四个数字
时间: 2024-02-15 10:03:58 浏览: 95
好的,下面是一个简单的实现:
```python
def password_complexity(password):
length = len(password)
upper_count = 0
lower_count = 0
digit_count = 0
for char in password:
if char.isupper():
upper_count += 1
elif char.islower():
lower_count += 1
elif char.isdigit():
digit_count += 1
return f"Length: {length}, Upper: {upper_count}, Lower: {lower_count}, Digit: {digit_count}"
```
你可以这样调用:
```python
password = "Abc123"
result = password_complexity(password)
print(result)
```
输出结果应该是:
```
Length: 6, Upper: 1, Lower: 2, Digit: 3
```
阅读全文