标签:else count print pre 字母 ascii letter str int
#习题7:求一个字符串中的字母个数函数需判断传入参数的类型。必须使用ascii来判断是否字母
s = "I am a 12 years old boy!" def letter_num(s): count=0 if isinstance(s,str): for i in s: if (ord(i)>=97 and ord(i)<=121) or (ord(i)>=65 and ord(i)<=90): count+=1 else: print("请传入一个字符串!") return -1 return count print(letter_num(s))
标签:else count print pre 字母 ascii letter str int
原文地址:https://www.cnblogs.com/wenm1128/p/10677426.html