python中输入字符串,统计字符串中大小写英文字母各有多少个?
展开全部
str_1=input("请输入一个字符串:")
numC=0
numS=0
numO=0
i=0
len_str=len(str_1)
while i<=len_str:
i += 1
if(str[i]>="A") and (str[i]<="Z"):
numC=numC+1
if(str[i]>="a") and (str[i]<="z"):
numS=numS+1
else:
numO=numO+1
print("您输入的字符串统计结果是:",len_str)
print("有%s个大写字母"%numC)
print("有%s个小写字母"%numS)
print("有%s个其他字母"%numO)
or
# python3.6
s = input("请输入一个字符串:")
a = b = c = 0
for i in s:
if 'A' <= i <= 'Z':
a += 1
elif 'a' <= i <= 'z':
b += 1
else:
c += 1
print("您输入的字符串统计结果是:",len(str))
print(f"有{a}个大写字母")
print(f"有{b}个小写字母")
print(f"有{c}个其他字母")
numC=0
numS=0
numO=0
i=0
len_str=len(str_1)
while i<=len_str:
i += 1
if(str[i]>="A") and (str[i]<="Z"):
numC=numC+1
if(str[i]>="a") and (str[i]<="z"):
numS=numS+1
else:
numO=numO+1
print("您输入的字符串统计结果是:",len_str)
print("有%s个大写字母"%numC)
print("有%s个小写字母"%numS)
print("有%s个其他字母"%numO)
or
# python3.6
s = input("请输入一个字符串:")
a = b = c = 0
for i in s:
if 'A' <= i <= 'Z':
a += 1
elif 'a' <= i <= 'z':
b += 1
else:
c += 1
print("您输入的字符串统计结果是:",len(str))
print(f"有{a}个大写字母")
print(f"有{b}个小写字母")
print(f"有{c}个其他字母")
2019-10-23
展开全部
str_1=input("请输入一个字符串:")
lower=0
upper=0
for i in str_1:
if i.islower():
lower += 1
elif i.isupper():
upper += 1
print("有%s个大写字母"%upper)
print("有%s个小写字母"%lower)
lower=0
upper=0
for i in str_1:
if i.islower():
lower += 1
elif i.isupper():
upper += 1
print("有%s个大写字母"%upper)
print("有%s个小写字母"%lower)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
# python中输入字符串,统计字符串中大小写英文字母各有多少个?
class countNum(object):
def __init__(self):
s = input("input a string")
self.s = s
def judge(self):
bigger = 0
smaller = 0
for i in self.s:
if i < 'A' or i > 'z':
continue
elif 'A' < i < 'Z':
bigger += 1
elif 'a' < i < 'z':
smaller += 1
return bigger, smaller
if __name__ == '__main__':
p = countNum()
big, small = p.judge()
print("大写字母%d个" % big)
print("小写字母%d个" % small)
class countNum(object):
def __init__(self):
s = input("input a string")
self.s = s
def judge(self):
bigger = 0
smaller = 0
for i in self.s:
if i < 'A' or i > 'z':
continue
elif 'A' < i < 'Z':
bigger += 1
elif 'a' < i < 'z':
smaller += 1
return bigger, smaller
if __name__ == '__main__':
p = countNum()
big, small = p.judge()
print("大写字母%d个" % big)
print("小写字母%d个" % small)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询