Author: Notus(hehe_xiao@qq.com)
Create: 2019-02-24
Update: 2019-02-24

环境

Python version: 3.7.1

代码如下(a.py)

'''
	利用函数对输入的字母和数字计数
	@Author: Notus(hehe_xiao@qq.com)
	@Create: 2019-02-24
	@Update: 2019-02-24
	@Version: 0.1
'''

import string

def letterCount(S):
	'''对字母计数'''
	count = 0
	for s in S:
		if s.lower() in string.ascii_lowercase:
			count += 1
	return count

def digitCount(S):
	'''对数字计数'''
	count = 0
	for s in S:
		if s in string.digits:
			count += 1
	return count

s = input("请输入任意内容:")
print("输入的数总长 {}, 其中含字母 {} 个, 数字 {} 个".format(len(s), letterCount(s), digitCount(s)) )

运行

C:\Users\Notus\Desktop>python a.py
请输入任意内容: perw 5;6okofcva 2309z9k 6
输入的数总长 26, 其中含字母 13 个, 数字 8 个

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2021-08-18
  • 2021-07-14
相关资源
相似解决方案