|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 白本羽 于 2021-4-11 10:11 编辑
请用已经学过的只是编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
a)每位密码为单个小写字母
b)没为密码的左右两边均有且只有三个大写字母
passwd=''
for each in str1:
if each.islower(): #判断取出的是否为小写字母
position=str1.index(each)
front=position-3
rear=position+3
if str1[front:position-1].isupper() and str1[position+1:rear].isupper(): #判断前三位和后三位是否都为大写字母
if str1[front-1].isupper() == False and str1[rear+1].isupper() == False: #判断前第4位和后第4位是否都不为大写字母
passwd += each
print(passwd)
str1是小甲鱼给的字符,已经定义过了,以上是我的代码,运行没有报错,但是输出为空,不知道为什么,求解答
当然能用了
- str1 = str1.replace('\n','').replace('\r','')
- passwd=''
- i=0
- for each in str1:
- i += 1
- if each.islower():
- position=str1.index(each,i-1)
- front=position-3
- rear=position+3
- if str1[front:position].isupper() and str1[position+1:rear+1].isupper():
- if str1[front-1].isupper() == False and str1[rear+1].isupper() == False:
- passwd += each
- print(passwd)
复制代码
你问题出在对str1的切片处理上,你看看我切的是啥,你切的是啥
|
|