|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
题目:请在字符串中找出密码,密码符合以下规律:
1.每位密码为单个小写字母;
2.每位密码字母的左右两边均有且只有3个大写字母
问题:好不容易读懂了大部分代码,但最终运行时没显示结果,究竟是为什么呢?请赐教,感谢!
str1 = '''AAAaAAAbAAAcAAAdAAAAeAA'''
countA = 0 #统计前三个字母为大写时计数
countB = 0 #满足前三个为大写字母后跳转条件用
countC = 0 #统计后三个字母为大写时计数
length = len(str1)
for i in range(length):
if str1[i] == '\n': #换行则重新执行循环
continue
if str1[i].isupper(): #字符为大写时执行
if countB == 1: #countB为1时统计countC的数量
countC += 1
countA = 0
else:
countA += 1 #否则重新统计countA的数量
continue
if str1[i].islower() and countA == 3: #字符为小写,且countA为3时执行
countB = 1
countA = 0
target = i
continue
if str1[i].islower() and countC == 3: #字符为小写,且countC为3时执行
print(str1[target],end='')
countA = 0 #不符合上述条件时countA,B,C置0
countB = 0
countC = 0
附上了注释,但打印出的结果为:ac 。而不是abc
希望帮忙看看!谢谢大家 |
|