|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
题:
我的解题思路:
1.先把小写字母的字符找到,把其字符的位置存在一个列表中
2.检查小写字母前后是不是大写
3。把符合条件的值打出来
- a = '''粘贴字符'''
- length = len(a)
- temp = []
- for i in range(length):
- if a[i] == '\n':
- continue
- for each in a[i]:
- if a[i].islower() == True and i + 4 <= length and i - 4 >=0 :
- temp.append(i)
- length1 = len(temp)
- for i1 in range(length1):
- if a[temp[i1]+1].islower() == False \
- and a[temp[i1]+2].islower() == False \
- and a[temp[i1]+3].islower() == False \
- and a[temp[i1]-1].islower() == False \
- and a[temp[i1]-2].islower() == False \
- and a[temp[i1]-3].islower() == False \
- and a[temp[i1]-4].islower() == True \
- and a[temp[i1]+4].islower() == True:
- print(a[temp[i1]],end="")
复制代码
结果:
多了个u和d,搞不明白啊
我最近也被这题困扰了很久,问题和你一样,也是多了俩个字母,最后幸亏得到了大神的点播
我看了下你的代码,和我出现的问题基本一样,都是因为你在判断小写字母前面和后面三个字符是否为大写的时候,忽略了换行符‘\n’在前后三个字符里的情况,你可以在a被定义后加上一行:
或者其实你把判断前后三个字符是否为大写写成这样:
- if a[temp[i1]+1].isupper() == True \
- and a[temp[i1]+2].isupper() == True \
- and a[temp[i1]+3].isupper() == True \
- and a[temp[i1]-1].isupper() == True \
- and a[temp[i1]-2].isupper() == True \
- and a[temp[i1]-3].isupper() == True \
- and a[temp[i1]-4].islower() == True \
- and a[temp[i1]+4].islower() == True:
复制代码
这样也就可以了
谢谢!单纯是想巩固自己学的内容,表达错误或者不好的地方忘谅解,另 我自己写的代码是这样的:
- str2 = '粘贴字符'
- #str2 = str2.replace('\n', '')
- lenght = len(str2)
- for i in range(3,lenght-4):
-
- x = str(str2[i]) #定义字符x
- y = str(str2[i-3:i]) #定义字符x的前三个字符
- z = str(str2[i+1:i+4]) #定义字符x的后三个字符
- q = y+z
- a = str(str2[i-4]) #定义字符x前面第四个字符
- b = str(str2[i+4]) #定义字符x后面第四个字符
- if x.islower() == True and q.isupper() == True and '\n' not in str(q) and \
- a.isupper() == False and b.isupper() == False:
- print(x,end='')
复制代码
|
|