ffff‘ 发表于 2021-1-15 14:41:31

python问题求助!

本帖最后由 ffff‘ 于 2021-1-15 14:43 编辑

请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
    a) 每位密码为单个小写字母
    b) 每位密码的左右两边均有且只有三个大写字母
str1 = '''ABSaDKSbRIHcRHGcdDIF'''
length = len(str1)
for each in range(3,length-2):
    if str1 == '\n':
      continue
    if str1.islower():
      if str1.isupper() and str1.isupper()and str1.isupper()and str1.isupper()and str1.isupper()and str1.isupper():
            if str1.isupper() or str1.isupper():
                continue
            else:
                print(str1,end="")
print("\n")

上面是我的代码,但是“a”字符出不来,我该怎么改进呢大佬们

jackz007 发表于 2021-1-15 14:50:03

str1 = '''ABSaDKSbRIHcRHGcdDIF'''
s , p = 'a' + ''.join(str1 . split('\n')) + 'a' , ''
for i in range(4 , len(str1) - 4):
    if s . islower() and s . isupper() and s . islower() and s . isupper() and s . islower():
      p += s
print(p)
页: [1]
查看完整版本: python问题求助!