The following program has an error :
new += lists[int(j)]+"-";
UnboundLocalError: local variable 'new' referenced before assignment
But when I put the sentence " new = '' " in the main() function, the program
run normally.
Please tell me why? Isn't variable new in the following program is a global
variable?
the program is:
lists = ['zero','one','two','three','four','five','six','seven','eight','nine'];
new = "";
def main():
while True:
try:
iput = int(raw_input('Please input a int(0~1000): '))
if not 0<=iput<=1000:
continue
except:
continue
break
iput = str(iput)
for j in iput:
new += lists[int(j)]+"-";
print new[0:-1];
if __name__ == "__main__":
main();
daedae11
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor