solution.md 1.5 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# 检查密码强度

<p>定义一个名为“isStrongPassword”的函数&#xff0c;该函数将字符串作为参数。功能然后将检查所提供的字符串是否满足以下条件&#xff0c;以检查是否为强 
密码&#xff1a;
1.必须至少包含1个大写和小写字母的组合
2.必须至少包含3位数字
3.必须至少包含3个特殊字符&#xff08;包括空格&#xff09;
4.密码长度必须至少12个字符
该函数将返回一个布尔值&#xff0c;即如果满足所有条件则返回True或返回False
确保使用可能返回False值的每个可能的输入来测试函数也一样</p>

## template

```python
def isStrongPassword(pwd):
	chars = list(pwd)
	upper = [c for c in chars if 'A' <= c and c <= 'Z']
	lower = [c for c in chars if 'a' <= c and c <= 'z']
	digit = [c for c in chars if '0' <= c and c <= '9' ]
	symbol = [c for c in chars if not ('A' <= c and c <= 'Z' or 'a' <= c and c <= 'z' or '0' <= c and c <= '9')] 
	strong = len(upper) >= 1 and len(lower) >= 1 and len(digit) >= 3 and len(symbol) >= 3 and len(pwd) >= 12
	return strong
print(isStrongPassword("Str0n9P@$$w0rd"))
print(isStrongPassword("StrongPassword"))
print(isStrongPassword("Stron9P@$$0rd"))
print(isStrongPassword("Str0n9Pass0rd"))
print(isStrongPassword("str0n9p@$$0rd"))
print(isStrongPassword("Str0n9P@$$"))
print(isStrongPassword("12345678"))
每日一练社区's avatar
每日一练社区 已提交
30
print(isStrongPassword("~!@#$$%^&*()_+"))
每日一练社区's avatar
每日一练社区 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
print(isStrongPassword("STRONGPASSWORD"))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```