019作业:判断字符数量问题
本帖最后由 159328404 于 2020-9-21 14:35 编辑def count(*params):
count1 = 0
count2 = 0
count3 = 0
count4 = 0
length1 = len(params)
for each1 in range(length1):
length2 = params
for each2 in range(length2):
if params.isalpha() == 1:
count1 += 1
elif params.isspace() == 1:
count2 += 1
elif params.isdigit() == 1:
count3 += 1
else:
count4 += 1
print('第' + str(each1+1) + '个字符串有:英文字母' + count1 + '个,数字' + coun3 + '个,空格' + count2 + '个,其他字符' + count4 + '个.')
count('i love 123-+*/')
为什么会报错啊。。。{:5_99:} def count(*params):
count1 = 0
count2 = 0
count3 = 0
count4 = 0
length1 = len(params)
for each1 in range(length1):
length2 = len(params)
for each2 in range(length2):
if params.isalpha() == 1:
count1 += 1
elif params.isspace() == 1:
count2 += 1
elif params.isdigit() == 1:
count3 += 1
else:
count4 += 1
print('第' + str(each1) + '个字符串有:英文字母' + str(count1) + '个,数字' + str(count3) + '个,空格' + str(count2) + '个,其他字符' + str(count4) + '个.')
count('i love 123-+*/')
第0个字符串有:英文字母5个,数字3个,空格2个,其他字符4个.
页:
[1]