[python practice questions] program 17

#Title : Enter a line of characters and count the number of English letters, spaces, numbers and other characters in it. 

s = input( ' Please enter a string: ' )

alf = 0
space = 0
digi = 0
other = 0

for i in s:
    if i.isalpha():
        alf += 1
    elif i.isspace():
        space += 1
     elif i.isdigit():
        digi += 1
    else:
        other += 1

print ('alf = %s'% alf,'space = %s'% space ,'digi = %s'% digi, 'other = %s'%other)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325075055&siteId=291194637