热门

最新

红包

立Flag

投票

同城

我的

发布
2401_83576022
2401_83576022
1 年前
true2401_83576022

Python统计字符个数,计算结果一直不对怎么办,麻烦大佬捞捞看看哪里错了

n=input("请输入一串字符:")
letter=dight=blank=others=0
for i in n:
if ord('a')<=ord('i')<=ord('z') or ord('A')<=ord('i')<=ord('Z'):
letter=letter+1
elif ord('0')<=ord('i')<=ord('9'):
dight=dight+1
elif ord('i')==ord(' '):
blank=blank+1
else:
others=others+1
print("这串字符中字母的个数为:{},数字的个数为:{},空格的个数为:{},其他字符的个数为:{}".format(letter,dight,blank,others))

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
Greetings from IAEEEE! 2024 3rd Conference on Materials Science and Engineering (CoMSE 2024) will be held in Johannesburg, South Africa from September 13-15, 2024. The conference is calling for papers related to the subjects of materials science and engineering . We look forward to your submission!(more information: www.icomse.org)
立即登录