【发布时间】:2019-09-03 17:14:57
【问题描述】:
这是我的代码:
while counter <= len(titles):
currenttime = [perc[counter], fails[counter], titles[counter]]
print(currenttime)
for percent, fail, title in currenttime:
当我运行它时,我得到一个值错误显示
ValueError: not enough values to unpack (expected 3, got 2)
但是当我打印当前时间时,我得到了
['67', '1', 'subsection']
对我来说,这看起来像是 3 个值,但显然我错了,有人可以启发我吗?我环顾四周,但没有找到好的答案。 任何帮助将不胜感激。谢谢
代码上下文:
n = 0
perc = list()
while n < len(piedata):
perc.append(piedata[n+2])
n += 3
print (perc)
n = 0
fails = list()
while n < len(piedata):
fails.append(piedata[n+1])
n += 3
print(fails)
n = 0
titles = list()
while n < len(piedata):
titles.append(piedata[n])
n += 3
print(titles)
counter = 0
while counter <= len(titles):
currenttime = [perc[counter], fails[counter], titles[counter]]
print(currenttime)
for percent, fail, title in currenttime:
piedata = [percent, (100-percent)]
fig = matplotlib.figure.Figure(figsize=(5, 5))
ax = fig.add_subplot(111)
ax.pie(piedata) # this is the information that the circle diagram will be made out of
ax.legend([('amount of attempts:', NOTT), ('amount of fails', fail)])
circle = matplotlib.patches.Circle((0, 0), 0.7, color='white')
ax.add_artist(circle)
# this is the code for actually putting the circle diagram/pie chart on the screen
canvas = FigureCanvasTkAgg(fig, master=window)
canvas.get_tk_widget().pack()
canvas.draw()
Label(window, text=(title, title), bg='light blue').pack()
counter += 1
window.mainloop()
print(percent)
print(fail)
【问题讨论】:
标签: python for-loop valueerror