|
|
5鱼币
def judge(*str1):
n = 0
while n <= len(str1):
num = 0
strN = 0
TabN = 0
Och = 0
m = 0
for m in range(len(str1[n])):
if ord(str1[n][m]) in range (48,58): #看有几个数字
num += 1
elif ord(str1[n][m]) in range(65,91) or ord(str1[n][m]) in range(97,123): #有几个字母
strN += 1
elif ord(str1[n][m]) == 32:
TabN += 1
else:
Och += 1
print('第 %d 个字符串共有:英文字母 %d 个,数字 %d 个,空格 %d 个,其他字符 %d 个' % ( n, strN,num,TabN,Och ))
n += 1
continue
strA = input('请输入任意个字符串:')
judge(strA)
查看有几个字符,数字, 空格的,但是错了,
Traceback (most recent call last):
File "H:/Python34/class 2.py", line 22, in <module>
judge(strA)
File "H:/Python34/class 2.py", line 9, in judge
for m in range(len(str1[n])):
IndexError: tuple index out of range |
最佳答案
查看完整内容
要想有多个元素,方法有3:
1.一次用多个input
2.for或while循环
3.把一个input结果拆分,这里用逗号
|