鱼C论坛

 找回密码
 立即注册
查看: 4476|回复: 8

《零基础》第20讲,最后一题:找出隐藏在长字符串中的密码

[复制链接]
发表于 2016-7-20 17:07:06 | 显示全部楼层 |阅读模式

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

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

x
就是下面这个题,密码隐藏点包含两个规律的。
请问那么代码如何理解!
我是这样写的,感觉差别很大啊!!!
>>> def findcode(str1):
    length=len(str1)
    list1=[]
    for each in str1[3:length-3]:
        if each.islower():
            index=str1.find(each)
            if (str1[index-3:index-1].isupper())and(str1[index+1:index+3].isupper()):
                list1.append(each)

题目

题目
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-7-20 17:20:55 | 显示全部楼层
你的程序考虑到两边有3个大写字母,但没考虑只有三个。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-20 20:55:51 | 显示全部楼层
冬雪雪冬 发表于 2016-7-20 17:20
你的程序考虑到两边有3个大写字母,但没考虑只有三个。

能举个栗子密码是怎样的嘛?另外为和会有换行符号\n?是每一行至多1个密码的意思?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-7-20 21:18:51 | 显示全部楼层
george123 发表于 2016-7-20 20:55
能举个栗子密码是怎样的嘛?另外为和会有换行符号\n?是每一行至多1个密码的意思?

AAAaBBB则a是
AAAAaBBB则a不是
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-20 21:21:18 | 显示全部楼层
冬雪雪冬 发表于 2016-7-20 21:18
AAAaBBB则a是
AAAAaBBB则a不是

懂了,谢谢谢谢!!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-20 22:05:30 | 显示全部楼层
冬雪雪冬 发表于 2016-7-20 21:18
AAAaBBB则a是
AAAAaBBB则a不是

我又改进了下我的程序,为和这个还是不可以?
def findcode(str1):
        length=len(str1)
        str2=str1[3:length-3]
        for each in str2:
                if each.islower():
                        index=str1.find(each)
                        s1=str1[index-3:index-1]
                        s2=str1[index+1:index+3]
                        if ('\n' in s1 )or ('\n' in s2):
                                continue
                        elif (s1.isupper())and(s2.isupper()):
                                if index==3 or index==length-3:
                                        print(each,end=' ')
                                elif str1[index-4].islower() and str1[index+4].islower():
                                        print(each,end=' ')
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-7-20 22:07:58 | 显示全部楼层
george123 发表于 2016-7-20 22:05
我又改进了下我的程序,为和这个还是不可以?
def findcode(str1):
        length=len(str1)

我觉得可能还是有问题,我再想想!!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-7-21 15:59:14 | 显示全部楼层
复杂
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-29 23:01:59 | 显示全部楼层
楼主,找到问题答案了么?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-2-21 20:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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