设计一个函数,统计任意一串字符串中数字字符的个数
def numCount():python
count = 0 str = raw_input('please input something:') for i in str: if i.isdigit(): count+=1 print count
numCount()git
2,设计函数,统计任意一串字符串中每一个字母的个数,不区分大小写app
import stringide
def lettersCount():函数
list1=[] str = raw_input('please input something:') for i in str: if i.isalpha(): list1.append(i.lower()) for j in string.lowercase: n = list1.count(j) if not n: continue else: print '%s 的个数为%s' %(j,n)
lettersCount()this
2018-01-02 13:16 添加评论 评分设计
0agh353272297 code
一、设计一个函数,统计任意一串字符串中数字字符的个数orm
#!/usr/bin/env pythonutf-8
str1 = raw_input("请输入字符: ")
def iCount(s):
Count = 0 for i in s: if i.isdigit(): Count += 1 else: pass print "数字=%d" % (Count)
if name == 'main':
iCount(str)
二、设计函数,统计任意一串字符串中每一个字母的个数,不区分大小写
#!/usr/bin/env python
str1 = raw_input("请输入字符: ")
def strCount(s):
s =list( ''.join(s.split())) s1 = set(s) l = list(s1) t = {} for i in range(len(l)): num = 0 for j in reversed(range(len(s))): if l == s[j]: num = num + 1 s.pop(j) t[l] = str(num) return t
if name == 'main':
t = strCount(str1) print(t)
2018-01-02 17:38 添加评论 评分
0LINUX_A - 不要在最能吃苦的年龄选择安逸!
#!/usr/bin/env python
list1 = []
aa = raw_input("pls input sth: ")
for i in aa:
if i in "0123456789": list1.append(i)
print "the input number is {}".format(len(list1))
list1 = []
list2 = {}
aa = raw_input("pls input sth: ")
for i in aa:
if i.isalpha(): list1.append(i)
for i in list1:
list2 = list1.count(i)
for k,v in list2.iteritems():
print " total this character {} is {}".format(k,v)
2018-01-03 15:56 添加评论 评分
0zhouyuyao
设计一个函数,统计任意一串字符串中数字字符的个数
例如:
"adfdfjv1jl;2jlk1j2" 数字个数为3个
def countNum():
co = 0 s = input("Please input a string : ") for c in s: if c.isdigit(): co+=1 print("The string have {} number.".format(co))
countNum()
设计函数,统计任意一串字符串中每一个字母的个数,不区分大小写
例如:
"aaabbbcccaae111"
a 5个
b 3个
c 3个
e 1个
import re
def countNum():
a={} # s1='' s = input("Please input a string : ") s1=re.sub('[^a-zA-Z]','',s) a = {i: s.count(i) for i in s1} print(a)
countNum()