如何使用Python3实现输入一行字符,统计其中空格

时间:2024-07-17 14:32:12 励志句子

1、elseif(c=='')

2、digit++;

3、foriinstrs:#遍历字符串

4、for(inti=0;i

5、spa_count+=1

6、print("字符串s中,数字个数={},字母个数={},空格个数={},其他个数={}".format(int_count,str_count,spa_count,other_count))

7、printf("字符串中字母个数为:%d、数字个数为:%d、空格个数为:%d、其它字符个数为:%d.\n",zm,sz,kg,qt);

8、printf("英文字母:%d\n",letter);

9、#include

10、ifi.isdigit():#判断是否为数字

11、Python2的raw_input()以及Python3的input()获取的是整行的字符串。那么对于一行输入多值,例如:输入为一行,包括用空格分隔的三个整数,分别为a、b、c

12、space++;

13、else:

14、charpc[M];

15、else

16、#include

17、intletter=0,space=0,digit=0,other=0;

18、qt=len-zm-sz-kg;

19、if('a'

20、intzm=0,sz=0,kg=0,qt;

21、elifi.isspace():#判断是否为空格

22、//判断字符是否空格

23、while((c=getchar())!='\n')

24、printf("数字:%d\n",digit);

25、intlen=strlen(pc);

26、#defineM100

27、int_count+=1

28、if(isalpha(pc[i]))zm++;

29、strs=input("请输入字符串s:")

30、elseif('0'

31、#includevoidmain(){intletter,space,digit,other;charch;letter=space=digit=other=0;while((ch=getchar())!='\n'){if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')letter++;elseif(ch>='0'&&ch<='9')digit++;elseif(ch=='')space++;elseother++;}printf("字母:%d\n",letter)

32、;printf("数字:%d\n",digit)

33、other_count+=1

34、printf("\n输入字符串:");

35、#include

36、letter++;

37、//判断字符是否数字

38、printf("空格:%d\n",space);

39、gets(pc);

40、count_str(strs)

41、if(isdigit(pc[i]))sz++;

42、printf("其它字符:%d\n",other);

43、defcount_str(strs):int_count,str_count,spa_count,other_count=0,0,0,0

44、#include

45、if(pc[i]=='')kg++;

46、charc;

47、//判断字符是否字母

48、voidmain()

49、;printf("空格:%d\n",space)

50、str_count+=1

51、if__name__=="__main__":

52、elifi.isalnum():#判断是否为字母

53、other++;

54、;printf("其它字符:%d\n",other);}