結合ASCII表統計英文字母,漢字,數字,符號數:
text=‘中國+china2017是-*/OK很難a也不難’
要求:
①用循環語句判斷統計
②打印統計結果
text='中國+china2017是-*/OK很難a也不難'
Eng=0
ch=0
numb=0
sym=0
i=0
while i<len(text):
if ord(text[i])>127:
ch+=1
elif (ord(text[i])<123 and ord(text[i])>96):
Eng+=1
elif (ord(text[i])<90 and ord(text[i])>64):
Eng+=1
elif (ord(text[i])<58 and ord(text[i])>47):
numb+=1
else:
sym+=1
i+=1
print('英文字母數%d,漢字數%d,數字數%d,符號數%d'%(Eng,ch,numb,sym))
結果