|
发表于 2017-5-26 20:38:45
|
显示全部楼层
错误有几处我就不一一截图了,具体看代码
首先if else语句使用不当,其次第21行continue打错了,再有第32行str1[i+1].isupper()少了括号,另外else注意缩进
最后jjIIIoIIIkIII应该输出ok而你的代码只能输出o,需要改进
- str1='''jjIIIoIIIkIII''' #因篇幅有限,文字注明
- countA=0 #统计前面的大写字母数
- countB=0 #统计小写字母
- countC=0 #统计后面的大写字母数
- length=len(str1)
- i=0
- for i in range(length):
- if str1[i]=='\n':
- continue
- elif str1[i].isupper():
- if countB:
- countC=countC+1
- else:
- countC=0
- countA=countA+1
-
- elif str1[i].islower():
- if countA==3:
- if countB:
- countA=0
- continue
- else:
- countB=1
- target=i
- else:
- countA=0
- countB=0
- countC=0
-
-
- if ((countA==3) and (countC==3)):
- if ((i+1 != length) and (str1[i+1].isupper())):
- countA=0
- countB=0
- countC=0
-
-
- else:
- print(str1[target])
复制代码
|
|