思路:
1.input函数输入的为str类型,所以判断是否为数字时:
zifu[i]>=‘0’ and zifu[i]<=‘9’
0和9都为str类型
2.判断是否为字母,判断字符是否在‘a’和‘z’之间,若是则为小写字母,在‘A’和‘Z’之间为大写字母
zifu
=
input
(
"Please input something:"
)
#统计数字个数
num
=
0
#统计字母个数
zimu
=
0
#统计空格个数
blankspace
=
0
#统计其他字符个数
qita
=
0
for
i
in
range
(
len
(
zifu
)
)
:
if
zifu
[
i
]
>=
'0'
and
zifu
[
i
]
<=
'9'
:
num
+=
1
elif
zifu
[
0
]
==
' '
:
blankspace
+=
1
elif
(
zifu
[
i
]
>=
'a'
and
zifu
[
i
]
<=
'z'
)
or
(
zifu
[
i
]
>=
'A'
and
zifu
[
i
]
<=
'Z'
)
:
zimu
+=
1
else
:
qita
+=
1
print
(
'The length of zifu:'
,
len
(
zifu
)
)
print
(
'The number of number:'
,
num
)
print
(
'The number of blankspace:'
,
blankspace
)
print
(
'The number of character:'
,
zimu
)
print
(
'Else:'
,
qita
)