|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ffff‘ 于 2021-1-15 14:43 编辑
请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
a) 每位密码为单个小写字母
b) 每位密码的左右两边均有且只有三个大写字母
str1 = '''ABSaDKSbRIHcRHGcdDIF'''
length = len(str1)
for each in range(3,length-2):
if str1[each] == '\n':
continue
if str1[each].islower():
if str1[each-3].isupper() and str1[each-2].isupper()and str1[each-1].isupper()and str1[each+3].isupper()and str1[each+2].isupper()and str1[each+1].isupper():
if str1[each-4].isupper() or str1[each+4].isupper():
continue
else:
print(str1[each],end="")
print("\n")
上面是我的代码,但是“a”字符出不来,我该怎么改进呢大佬们
- str1 = '''ABSaDKSbRIHcRHGcdDIF'''
- s , p = 'a' + ''.join(str1 . split('\n')) + 'a' , ''
- for i in range(4 , len(str1) - 4):
- if s[i - 4] . islower() and s[i - 3 : i] . isupper() and s[i] . islower() and s[i + 1 : i + 4] . isupper() and s[i + 4] . islower():
- p += s[i]
- print(p)
复制代码
|
|