鱼C论坛

 找回密码
 立即注册
查看: 1302|回复: 1

[已解决]python问题求助!

[复制链接]
发表于 2021-1-15 14:41:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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”字符出不来,我该怎么改进呢大佬们
最佳答案
2021-1-15 14:50:03
  1. str1 = '''ABSaDKSbRIHcRHGcdDIF'''
  2. s , p = 'a' + ''.join(str1 . split('\n')) + 'a' , ''
  3. for i in range(4 , len(str1) - 4):
  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():
  5.         p += s[i]
  6. print(p)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-15 14:50:03 | 显示全部楼层    本楼为最佳答案   
  1. str1 = '''ABSaDKSbRIHcRHGcdDIF'''
  2. s , p = 'a' + ''.join(str1 . split('\n')) + 'a' , ''
  3. for i in range(4 , len(str1) - 4):
  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():
  5.         p += s[i]
  6. print(p)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-1 22:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表