|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
第20讲函数作业,问题见注释
str1 = '''输入的字符串'''
countA = 0 # 统计前边的大写字母
countB = 0 # 统计小写字母
countC = 0 # 统计后边的大写字母
length = len(str1)
for i in range(length):
if str1[i] == '\n':
continue
#下面这六行为什么不能把中间四行省略了?,if countB不是一定是false吗?
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
countB 有可能为 1,有可能为 0,而 if countB 等价于 if countB != 0,当 countB 不为 0 就执行 if 下的语句,否则执行 else 下的语句
|
|