来个大佬帮忙解答吧,是我们的作业,真的不知道怎么做了,直接甩代码,给我个机会吧,,,,,,
data = input("请输入字符串")
countDict = {
"upper":0, # 大写
"lower":0, # 小写
"digit":0, # 数字
"other":0, # 其他
}
# 遍历这个字符串
for s in data:
if ord("a") <= ord(s) <= ord("z"):
countDict["upper"] = countDict["upper"] + 1
elif ord("A") <= ord(s) <= ord("Z"):
countDict["lower"] = countDict["lower"] + 1
elif ord("0") <= ord(s) <= ord("9"):
countDict["digit"] = countDict["digit"] + 1
else:
countDict["other"] = countDict["other"] + 1
print("大写字母个数: ",countDict["upper"])
print("小写字母个数: ",countDict["lower"])
print("数字的个数: ",countDict["digit"])
print("其他的个数: ",countDict["other"])
如果觉得答案对你有帮助,请点击下采纳,谢谢~