Day3、Python
2016-04-01 09:54
453 查看
题目 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
1、程序分析
根据题意可知,需要用到字符串的操作方法。本题中要用到的三种方法如下:
a、检查字符串空格的方法:
实例:
b、检查字符串数字的方法:
实例:
c、检查字符串字母的方法:
实例:
2、程序实现
3、结果显示
1、程序分析
根据题意可知,需要用到字符串的操作方法。本题中要用到的三种方法如下:
a、检查字符串空格的方法:
实例:
b、检查字符串数字的方法:
实例:
c、检查字符串字母的方法:
实例:
2、程序实现
#Topic : 输入一行字符,分别统计出其中英文字母、 # 空格和其他字符的个数 #File Name : count_string.py #Author : Jack Cui #Created : 1 April 2016 str = input('please input a string:\n') letter = 0 space = 0 digit = 0 other = 0 for i in str: if i.isalpha(): letter += 1 elif i.isspace(): space += 1 elif i.isdigit(): digit += 1 else: other += 1 print('letter = %d,space = %d,digit = %d,other = %d' % (letter,space,digit,other))
3、结果显示
相关文章推荐
- python学习笔记(session)
- Python函数的各种参数(含星号参数)
- Python 基础 —— re:正则表达
- Python中遇到"UnicodeDecodeError: ‘gbk’ codec can’t decode bytes in position 2-3: illegal multibyte sequ
- python基于隐马尔可夫模型实现中文拼音输入
- Python 2.x vs Python 3.x(四)—— TypeError: unhashable type
- python3.5 + django1.9.1+mysql
- python中的条件语句,分支语句以及逻辑运算符和比较运算符
- 学python过程中遇到的一些问题及解决方法
- python爬虫(爬游民星空图片)_beautifulsoup爬虫模版
- python基于隐马尔可夫模型实现中文拼音输入
- python初识
- Python学习第十五天
- python 下载页面数据 到 execl表
- 一行 Python 实现并行化 -- 日常多线程操作的新思路
- Python学习笔记day11
- python 多继承(新式类) 三
- Python基础知识注意点
- Python写爬虫-爬甘农大学校新闻
- python STMP