DoubleS、Zhao 发表于 2020-10-27 14:12:23

麻烦各位大佬帮帮忙

def search(x , y):
    word = 'asdfghjklqwertyuiopzxcvbnmASDFGHJKLQWERTYUIOPMNBVCXZ'
    number = '0123456789'
    blank = ' '
    other_str = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''

    a = b = 0

    length1 = len(x)
    length2 = len(y)
    count1 = count2 = count3 = count4 = 0

    while a <= length1 - 1:
      if x in word:
            count1 += 1
      if x in number:
            count2 += 1
      if x in blank:
            count3 += 1
      if x in other_str:
            count4 += 1
      a += 1
    print('第1个字符串共有:英文字母',count1,'个,数字',count2,'个,空格',count3,'个,其他字符',count4,'个。')

    count11 = count22 = count33 = count44 = 0
    while b <= length2 - 1:
      if y in word:
            count11 += 1
      if y in number:
            count22 += 1
      if y in blank:
            count33 += 1
      if y in other_str:
            count44 += 1
      a += 1
    print('第2个字符串共有:英文字母',count11,'个,数字',count22,'个,空格',count33,'个,其他字符',count44,'个。')


x='jehfewu8349287]][][][][][]   '
y='3fnshgnn'

search(x,y)


各位帮我看一下为什么只能打印x内的内容,y里面的内容没有打印呢?


{:9_220:}

lirenbing01 发表于 2020-10-27 14:17:19

本帖最后由 lirenbing01 于 2020-10-27 14:18 编辑

print('第2个字符串共有:英文字母',count11,'个,数字',count22,'个,空格',count33,'个,其他字符',count44,'个。')
前一句 是b+=1
你用a+=1 就死循环在第二大段了

DoubleS、Zhao 发表于 2020-10-27 14:33:42

def search(x,y):
    word = 'asdfghjklqwertyuiopzxcvbnmASDFGHJKLQWERTYUIOPMNBVCXZ'
    number = '0123456789'
    blank = ' '
    other_str = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''

    a = b = 0

    length1 = len(x)
    length2 = len(y)
    count1 =count2=count3=count4=0

    while a <= length1 - 1:
      if x in word:
            count1 += 1
      if x in number:
            count2 += 1
      if x in blank:
            count3 += 1
      if x in other_str:
            count4 += 1
      a += 1
    print('第1个字符串共有:英文字母',count1,'个,数字',count2,'个,空格',count3,'个,其他字符',count4,'个。')

    count11 =count22=count33=count44=0
    while b <= length2 - 1:
      if y in word:
            count11 += 1
      if y in number:
            count22 += 1
      if y in blank:
            count33 += 1
      if y in other_str:
            count44 += 1
      b += 1
    print('第2个字符串共有:英文字母',count11,'个,数字',count22,'个,空格',count33,'个,其他字符',count44,'个。')


x='jehfewu8349287]][][][][][]   '
y='3fnshgnn'

search(x,y)

jackz007 发表于 2020-10-27 14:38:50

本帖最后由 jackz007 于 2020-10-27 14:40 编辑

#-*-coding:gbk-*-
def search(* x):
    c = 0
    for s in x:
      cc = sum(1 for e in s if e . isalpha())
      cd = sum(1 for e in s if e . isdigit())
      cb = sum(1 for e in s if e . isspace())
      co = len(s) - cc - cd - cb
      c += 1
      print('第' , c , '个字符串共有:英文字母', cc ,'个,数字', cd ,'个,空格', cb ,'个,其他字符',co ,'个。')         
x='jehfewu8349287]][][][][][]   '
y='3fnshgnn'
search(x,y)
页: [1]
查看完整版本: 麻烦各位大佬帮帮忙