How can I find the remainder when dividing 2 integers

Diez B. Roggisch deets at nospam.web.de
Sun Feb 26 15:36:48 EST 2006


silverburgh.meryl at gmail.com schrieb:
> okay, I try you suggestion, and re-write my code like this:
> colors = ["#ff0000", "#00FF00", "#0000FF"]
> colorIndex = 0
> 
> def getText(nodelist):
> 
> 
>              for str in strings:
> 
>                      print colors[colorIndex  % colors.length]
>                      colorIndex += 1
> 
> but i get this error:
>    print colors[colorIndex  % colors.length]
> UnboundLocalError: local variable 'colorIndex' referenced before
> assignment

If I take your code, it works for me.

Diez



More information about the Python-list mailing list