I have a list of integer percentages which I need to print using the following pattern:
The index of a value, a tab (8 spaces), a '*' printed for each percentage point
also if the value for an index is 0, print ‘less than 1 percent’
I have tried this code:
for b in new_tally:
if b > 0:
print new_tally[b], \t, '*' * b
else:
print 'Less than 1% of words had this length'
However I keep getting the error code: list index out of range.
I do not understand this at all, can someone point out what I have done wrong?
I think the code you wanted was:
The cause of the original traceback is that list members are looked up using square brackets instead of parentheses.
new_tally(i)is a function call.new_tally[i]is an indexed lookup.