python` 发表于 2020-3-25 18:22:39

python第020讲问题

当i是小写字母的时候为什么countB会变成1[图片]

countA = 0# 统计前边的大写字母
countB = 0# 统计小写字母
countC = 0# 统计后边的大写字母
length = len(str1)

for i in range(length):
    if str1 == '\n':
      continue

    """
    |如果str1是大写字母:
    |-- 如果已经出现小写字母:
    |-- -- 统计后边的大写字母
    |-- 如果未出现小写字母:
    |-- -- 清空后边大写字母的统计
    |-- -- 统计前边的大写字母
    """
    print('我是小写字母', countB)
    print('我是0', str1)
    if str1.isupper():
      print('我是1', str1)
      if countB:
            print('我是2', str1)
            countC += 1
      else:
            print('我是3', str1)
            countC = 0
            countA += 1

我是小写字母 0
我是0 A
我是1 A
我是3 A
我是小写字母 0
我是0 C
我是1 C
我是3 C
我是小写字母 0
我是0 F
我是1 F
我是3 F
我是小写字母 0
我是0 l
我是小写字母 1
我是0 C
我是1 C
我是2 C
我是小写字母 1
我是0 T
我是1 T
我是2 T
我是小写字母 1
我是0 L
我是1 L
我是2 L
我是小写字母 0
我是0 I
我是1 I
我是3 I
我是小写字母 0
我是0 Q
我是1 Q
我是3 Q
我是小写字母 0

永恒的蓝色梦想 发表于 2020-3-25 19:46:05

没明白你的问题

_荟桐_ 发表于 2020-3-25 20:06:28

这个代码不完整吧???{:10_258:}

python` 发表于 2020-3-25 20:53:37

_荟桐_ 发表于 2020-3-25 20:06
这个代码不完整吧???

countA = 0# 统计前边的大写字母
countB = 0# 统计小写字母
countC = 0# 统计后边的大写字母
length = len(str1)

for i in range(length):
    if str1 == '\n':
      continue

    """
    |如果str1是大写字母:
    |-- 如果已经出现小写字母:
    |-- -- 统计后边的大写字母
    |-- 如果未出现小写字母:
    |-- -- 清空后边大写字母的统计
    |-- -- 统计前边的大写字母
    """
    print('我是小写字母', countB)
    print('我是0', str1)
    if str1.isupper():
      print('我是1', str1)
      if countB:
            print('我是2', str1)
            countC += 1
      else:
            print('我是3', str1)
            countC = 0
            countA += 1

    """
    |如果str1是小写字母:
    |-- 如果小写字母前边不是三个大写字母(不符合条件):
    |-- -- 清空所有记录,重新统计
    |-- 如果小写字母前边是三个大写字母(符合条件):
    |-- -- 如果已经存在小写字母:
    |-- -- -- 清空所有记录,重新统计(出现两个小写字母)
    |-- -- 如果该小写字母是唯一的:
    |-- -- -- countB记录出现小写字母,准备开始统计countC
    """
    if str1.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

    """
    |如果前边和后边都是三个大写字母:
    |-- 如果后边第四个字母也是大写字母(不符合条件):
    |-- -- 清空记录B和C,重新统计
    |-- 如果后边仅有三个大写字母(符合所有条件):
    |-- -- 打印结果,并清空所有记录,进入下一轮统计
    """
    if countA == 3 and countC == 3:
      if i+1 != length and str1.isupper():
            countB = 0
            countC = 0
      else:
            print(str1, end='')
            countA = 3
            countB = 0
            countC = 0

_荟桐_ 发表于 2020-3-26 07:21:37

   if str1.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
str1是小写字母且countA为3,countB为0时

python` 发表于 2020-3-26 07:30:58

_荟桐_ 发表于 2020-3-26 07:21
if str1.islower():
      if countA != 3:
            countA = 0


我想问countB是什么从0变1的

_荟桐_ 发表于 2020-3-26 08:17:57

python` 发表于 2020-3-26 07:30
我想问countB是什么从0变1的

str1是小写字母且countA为3,countB为0时countB就变成1了

冰河星云 发表于 2020-3-26 08:19:07

有认真学习!{:10_275:}
页: [1]
查看完整版本: python第020讲问题