|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我自己的代码如下:
- def find_secret(input_str):
- result = []
- length = len(input_str)
- for i in range(length-1):
- temp = input_str[i]
- if temp.islower():
- if (i-3) > 0 and (i+3) < (length-1):
- temp1 = input_str[i-3:i] #这些应该都大写#
- temp2 = input_str[i+1:i+4] #这些同上#
- temp3 = input_str[i-4]
- temp4 = input_str[i+4] #34应该都是小写#
- if temp1.isupper() and temp2.isupper() and temp3.islower() and temp4.islower():
- result.append(temp)
- else:
- pass #上面是判断小写字母在中间的情况,下面两大段代码判断小写字母分别在头在尾的情况#
- #下面判断第四个字母正好是第一个小写字母时的情况#
- elif (i-3) == 0: #说明他是第四个字母,第一个小写字母,判断前三和后三是否均为大写#
- other1 = input_str[0:3]
- other2 = input_str[4:7] #12应该都是大写#
- other3 = input_str[7] #这个应该是小写了,后三位大写的再后一位#
- if other1.isupper() and other2.isupper() and other3.islower():
- result.insert(0,input_str[3]) #如果是,它肯定是第一个小写字母,即密码的第一位#
- elif (i-3) <0: #小写字母出现在了前三位字母中,略过#
- pass
- #下面判断倒数第四个字母是小写字母时的情况(最后一个小写字母)#
- elif i == (length-4):
- other4 = input_str[(length-7):(length-4)] #小写字母前三位字母#
- other5 = input_str[(length-3):] #小写字母后三位字母,即字符串的最后三个字母#
- other6 = input_str[length-8] #小写字母向前的第四个字母是否也为小写#
- if other4.isupper() and other5.isupper() and other6.islower():
- result.append(input_str[length-4])
- else:
- pass
- print(str(result))
- input_str = input('输入字符串')
- print(find_secret(input_str))
复制代码
我的问题:导入我自己写的实验用的例子以及小甲鱼老湿在本题答案中的实验用的字符串,结果没问题,都可以得到正确的结果,附加一个None
但是导入小甲鱼老湿给的附加文件中的那一长串字符串,得到了一个空列表和一个None
百思不得其解,用一些简单的例子实验可以成功,用那一长串却不行
求大佬解答
1,不要在 input 时直接复制长字符串进去,input 只会读取第一行
要么把这个字符串搞成变量,用三引号,要么从文件里面读取
2,因为你这个函数没有返回值,可你调用时还是使用了 print(find_secret(input_str))
这样的调用方法。
直接 find_secret(input_str) 调用就行了
|
|