打印直方图

2024-06-28 19:44:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个整数百分比列表,需要使用以下模式打印:

The index of a value, a tab (8 spaces), a '*' printed for each percentage point

如果索引值为0,则打印“小于1%”

我试过这个密码:

for b in new_tally:
    if b > 0:
        print new_tally[b], \t, '*' * b
    else:
        print 'Less than 1% of words had this length'

但是我总是得到错误代码:列表索引超出范围。

我一点也不明白,有人能指出我做错了什么吗?


Tags: ofthe列表newforindexvalue模式