0
我不確定在那裏我得到這個錯誤:Python類型錯誤:int對象不是可迭代
Traceback (most recent call last):
File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 78, in <module>
main()
File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 74, in main
bars(words)
File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 62, in bars
init(words, lst)
File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 38, in init
freqLegend(words,val, lst)
File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 54, in freqLegend
freqLegend(words, val/1.5, counter-1)
File "C:/Users/Coscio/PycharmProjects/unigram/letterHist.py", line 53, in freqLegend
back((max(lst)*1000)/10)
TypeError: 'int' object is not iterable
我認爲它在我服用LST的最大我freqLegend功能發生和除以10但我沒有在這一點迭代任何事情,我不能找到爲什麼我得到這個錯誤。
from letterFreq import *
from turtle import *
def init(words, lst):
val = max(lst)
print(val)
speed(0)
setup (width=600, height=600, startx=0, starty=0)
up()
lt(180)
forward(200)
lt(90)
forward(100)
lt(90)
down()
forward(400)
up()
forward(-400)
lt(90)
down()
forward(val*1000)
up()
back(val*1000+20)
rt(90)
forward(200)
write("A B C D E F G H I J K L M N O P Q "
"R S T U V W X Y Z", True, align="center")
goto(-200,-100)
lt(90)
forward((val*1000)/2)
lt(90)
forward(60)
write("Frequency", True, align="center")
rt(90)
goto(-200,153)
freqLegend(words,val, lst)
def freqLegend(words, val, lst, counter = 10):
if counter == 0:
goto(-200,-100)
return
elif counter > 0:
up()
lt(90)
down()
forward(30)
write(round(val, 3))
back(30)
rt(90)
back((max(lst)*1000)/10)
freqLegend(words, val/1.5, counter-1)
def bars(words):
lstFreq = []
for letters in letterFreq(words):
lstFreq.append(letterFreq(words)[letters])
lst = lstFreq
init(words, lst)
for i in lst:
down()
forward(i*1000)
rt(90)
forward(14)
left(90)
back(i*1000)
def main():
filename = "data/very_short.csv"
words = readWordFile(filename)
bars(words)
input("enter to close")
if __name__ == '__main__':
main()