[Tutor] An unknown error in my program

Alan Gauld alan.gauld at btinternet.com
Sun Dec 25 15:49:08 CET 2011


On 25/12/11 10:18, daedae11 wrote:
> The following program has an error :
> new += lists[int(j)]+"-";
> UnboundLocalError: local variable 'new' referenced before assignment

Others have answered the question for you however there are two 
additional points to make:

1) Always send the complete erroir message not just the last line.
2) You do not need semi-colons at the end of lines in Python.

> lists =
> ['zero','one','two','three','four','five','six','seven','eight','nine'];
> new = "";

No need for them here

> for j in iput:
> new += lists[int(j)]+"-";
> print new[0:-1];
> if __name__ == "__main__":
> main();

Nor here.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list