鱼C论坛

 找回密码
 立即注册
查看: 2296|回复: 3

[已解决]麻烦各位大佬帮帮忙

[复制链接]
发表于 2020-10-27 14:12:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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

  6.     a = b = 0

  7.     length1 = len(x)
  8.     length2 = len(y)
  9.     count1 = count2 = count3 = count4 = 0

  10.     while a <= length1 - 1:
  11.         if x[a] in word:
  12.             count1 += 1
  13.         if x[a] in number:
  14.             count2 += 1
  15.         if x[a] in blank:
  16.             count3 += 1
  17.         if x[a] in other_str:
  18.             count4 += 1
  19.         a += 1
  20.     print('第1个字符串共有:英文字母',count1,'个,数字',count2,'个,空格',count3,'个,其他字符',count4,'个。')

  21.     count11 = count22 = count33 = count44 = 0
  22.     while b <= length2 - 1:
  23.         if y[b] in word:
  24.             count11 += 1
  25.         if y[b] in number:
  26.             count22 += 1
  27.         if y[b] in blank:
  28.             count33 += 1
  29.         if y[b] in other_str:
  30.             count44 += 1
  31.         a += 1
  32.     print('第2个字符串共有:英文字母',count11,'个,数字',count22,'个,空格',count33,'个,其他字符',count44,'个。')


  33. x='jehfewu8349287]][][][][][]   '
  34. y='3fnshgnn'

  35. search(x,y)
复制代码



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


最佳答案
2020-10-27 14:17:19
本帖最后由 lirenbing01 于 2020-10-27 14:18 编辑
  1. print('第2个字符串共有:英文字母',count11,'个,数字',count22,'个,空格',count33,'个,其他字符',count44,'个。')
  2. 前一句 是b+=1
复制代码

你用a+=1 就死循环在第二大段了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-10-27 14:17:19 | 显示全部楼层    本楼为最佳答案   
本帖最后由 lirenbing01 于 2020-10-27 14:18 编辑
  1. print('第2个字符串共有:英文字母',count11,'个,数字',count22,'个,空格',count33,'个,其他字符',count44,'个。')
  2. 前一句 是b+=1
复制代码

你用a+=1 就死循环在第二大段了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-10-27 14:33:42 | 显示全部楼层
  1. def search(x,y):
  2.     word = 'asdfghjklqwertyuiopzxcvbnmASDFGHJKLQWERTYUIOPMNBVCXZ'
  3.     number = '0123456789'
  4.     blank = ' '
  5.     other_str = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''

  6.     a = b = 0

  7.     length1 = len(x)
  8.     length2 = len(y)
  9.     count1 =count2=count3=count4=0

  10.     while a <= length1 - 1:
  11.         if x[a] in word:
  12.             count1 += 1
  13.         if x[a] in number:
  14.             count2 += 1
  15.         if x[a] in blank:
  16.             count3 += 1
  17.         if x[a] in other_str:
  18.             count4 += 1
  19.         a += 1
  20.     print('第1个字符串共有:英文字母',count1,'个,数字',count2,'个,空格',count3,'个,其他字符',count4,'个。')

  21.     count11 =count22=count33=count44=0
  22.     while b <= length2 - 1:
  23.         if y[b] in word:
  24.             count11 += 1
  25.         if y[b] in number:
  26.             count22 += 1
  27.         if y[b] in blank:
  28.             count33 += 1
  29.         if y[b] in other_str:
  30.             count44 += 1
  31.         b += 1
  32.     print('第2个字符串共有:英文字母',count11,'个,数字',count22,'个,空格',count33,'个,其他字符',count44,'个。')


  33. x='jehfewu8349287]][][][][][]   '
  34. y='3fnshgnn'

  35. search(x,y)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-27 14:38:50 | 显示全部楼层
本帖最后由 jackz007 于 2020-10-27 14:40 编辑
  1. #-*-coding:gbk-*-
  2. def search(* x):
  3.     c = 0
  4.     for s in x:
  5.         cc = sum(1 for e in s if e . isalpha())
  6.         cd = sum(1 for e in s if e . isdigit())
  7.         cb = sum(1 for e in s if e . isspace())
  8.         co = len(s) - cc - cd - cb
  9.         c += 1
  10.         print('第' , c , '个字符串共有:英文字母', cc ,'个,数字', cd ,'个,空格', cb ,'个,其他字符',co ,'个。')           
  11. x='jehfewu8349287]][][][][][]   '
  12. y='3fnshgnn'
  13. search(x,y)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-28 21:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表