|
|
发表于 2019-10-3 23:54:04
|
显示全部楼层
本帖最后由 XiaoPaiShen 于 2019-10-4 00:01 编辑
- # str2 = str(input('请输入字符串:'))
- str2 = 'ABCaBCDbGHEcFGDdGGGeABC'
- length = len(str2)
- index = 2
- password = []
- if length < 7:
- print('此字符串中不可能含有密码!')
- else:
- for item in str2[3:-3]:
- index += 1
- if item.islower():
- prev = str2[index-3:index] #前面3个字符
- suff = str2[index+1:index+4] # 后面3个字符
- # print(prev, suff)
- if (not prev.isupper()) or (not suff.isupper()):
- continue
-
- if index > 3 and (length - index) > 4: # 中间字符,并且前后都有多于3个字符
- if str2[index-4].isupper() or str2[index+4].isupper():
- continue
- else:
- password.append(item)
- elif index == 3 and (length - index) > 4: # 左边只有3个
- if str2[index+4].isupper():
- continue
- else:
- password.append(item)
- elif index > 3 and (length - index) == 4: # 右边只有3个
- if str2[index-4].isupper():
- continue
- else:
- password.append(item)
- else: # 前后都只有3个字符
- password.append(item)
- print(password)
-
-
-
复制代码 |
|