|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
str1 = '''ABSaDKSbRIHcRHGcdDIF'''
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:
countC += 1
else:
countC = 0
countA += 1
if str1[i].islower():
if countA != 3:
countA = 0
countB = 0
countC = 0
else:
if countB:
countA = 0
countB = 0
countC = 0
else:
countB = 1
countC = 0
target = i
if countA == 3 and countC == 3:
if i+1 != length and str1[i+1].isupper():
countB = 0
countC = 0
else:
print(str1[target], end='')
countA = 3
countB = 0
countC = 0
《零基础入门学习Python》20讲的动动手最后一题
if i+1 != length and str1[i+1].isupper():
这一句一直理解不来,有人能指教下吗?
i+1!=length的判断是防止后面的str[i+1]访问越界。结合上面一行代码:'if countA == 3 and countC == 3:' str[i+1].isupper()是为了判断三个字母之后接的是否为大写字母,若后面是大写字母,则以这个字符向前数七个字符的这一段字符不是隐藏的密码。
|
|