Python入门练习: 练习实例七
目录 Python入门练习 Python入门练习 题目: 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 程序分析: 利用 while 或 for 语句,条件为输入的字符不为 '\n'。 str1=input('请输入 :') list1=[] num=0 letter=0 space=0 other=0 for i in str1: if i.isalpha(): #函数字母 num=num+1 elif i.isspace(): #判断空格 space=space+1 elif i.isdigit(): #判断数字 letter=letter+1 else: other=other+1 print('数字有',letter,'个') print('字母有',num,'个') print('空格有',space,'个') print('其他字符有',other,'个') 来源: CSDN 作者: Thinklov 链接: https://blog.csdn.net/u010244992/article/details/104591565