️小猪佩蕊 2019-11-16 20:43 采纳率: 100%
浏览 269
已采纳

各位大佬,下面的代码填空怎么做哇?

用函数实现统计字符串中,字母和数字及不包括子母及数字的个数,在函数外输入 字符串并输出统计结果。

def Dcount(str):

alph=digit=other=0

for i in str:

if______ .isalpha()==True:

alph+=1

elif______ .isdigit()==True:

digit+=1

else:other+=1

return alph,digit,other

x=(input())
print("alph=%d,digit=%d,other=%d"%Dcount(x))

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-11-16 21:28
    关注
    # -*- coding: UTF-8 -*-
    def Dcount(str):
        alph=digit=other=0
        for i in str:
            if i.isalpha()==True:
                alph+=1
            elif i.isdigit()==True:
                digit+=1
            else:
                other+=1
        return alph,digit,other
    
    x=(input())
    print("alph=%d,digit=%d,other=%d"%Dcount(x))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?