Hi,
This code generates the message "UnboundLocalError: local variable 'doubles' referenced before assignment" (line: if d[0] == d[1] and doubles == 2:) http://pastebin.com/mYBaCfj1 I think I have a fair picture of what it means but I would be very happy if someone could explain the difference between the two variables h and doubles in the code. Why is one accessible from the function but not the other? I looked into rules for namespaces but I'm still confused. Below is another sample of the code Cheers, Robert from random import * h = 6 doubles = 0 # current number of consecutive doubles def roll(): d = [randint(1, h), randint(1, h)] if d[0] == d[1] and doubles == 2: doubles = 0 return 0 elif d[0] == d[1] and doubles < 2: doubles += 1 return sum(d) else: return sum(d) for n in range(10): d = roll() print d
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor