我正在 Python 上编写一个脚本,你给出一个字符串,它会找到字符串中字母的数量,将其输入到一个列表中,然后将该列表相加。我的脚本运行器不断给出这个错误:
Traceback (most recent call last):
File "Untitled.py", line 9, in <module>
countersplit = len(tosplit[counter])
TypeError: 'int' object has no attribute '__getitem__'
我的代码如下:
userin = raw_input("Enter sentence: ")
split = userin.split()
tosplit = len(split)
print(tosplit)
counter = 0
countersplit = 0
while counter < tosplit:
countersplit = len(tosplit[counter])
wordcount = [countersplit]
print(wordcount)
print(countersplit)
counter = counter + 1
我能做些什么来解决这个问题?