|

楼主 |
发表于 2020-6-4 17:48:11
|
显示全部楼层
谢谢大佬的回复,可我想要的结果是list这个列表的每个数对应收集参数*param的每一个数,以下是我课后习题的代码,第19讲动动手,请帮我看看,该怎么修改呢?
- def count(*param):
- length = len(param)
- for m in range(length):
- letters = 0
- spaces = 0
- nums = 0
- others = 0
- for each in param[m]:
- if each.isalpha():
- letters += 1
- elif each.isdigit():
- nums += 1
- elif each == ' ':
- spaces += 1
- else:
- others += 1
- print('第 %d 个字符串共有 %d 个英文字母, %d 个数字, %d 个空格, %d 个其他字符' %(m+1, letters, nums, spaces, others))
- a = 1
- i = 0
- list = []
- last = '#'
- while a:
- string = str(input('请输入需要检查的所有字符串,回车键结束输入并开始输入下一个字符串,输入#结束所有输入:'))
- list.append(string)
- if last == list[i]:
- print('输入结束!')
- a = 0
- i += 1
- count(list)
复制代码 |
|