标签:style blog color for div sp log on c
题目:
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
def foo(a): l=len(a); letters=0; space=0; digit=0; others=0; for i in range(0,l): num=ord(a[i]) if num>=ord(‘a‘) and num<=ord(‘z‘) or num>=ord(‘A‘) and num<=ord(‘Z‘): letters=letters+1; elif num>=ord(‘0‘) and num<=ord(‘9‘): digit=digit+1; elif num==ord(‘ ‘): space=space+1; else: others=others+1; print letters,space,digit,others foo(‘sadfsa34564 ,.,.‘)
标签:style blog color for div sp log on c
原文地址:http://www.cnblogs.com/verstin/p/3969473.html