beats = 8 outside the function. inside add_one() I print(beats) then do beats = beats + 1. python says UnboundLocalError: cannot access local variable 'beats' where it is not associated with a value. I thought I paid for the eight beats when I put them outside.
assignment in the function makes that name local there unless you explicitly say otherwise. it hasn't yet been bound in that local scope at the print. put the starting count on the table as a parameter.
def add_one(beats): return beats + 1. kicks start at 8 and bells at 2. kicks = add_one(kicks), bells still 2. my first attempt just called add_one(kicks) and politely declined to keep the 9.
che, si lo hicieras global, ¿el segundo músico qué oiría? en la sala uno ensaya en ocho y el otro en dos y no quiero que el parche de uno le escriba la partitura al otro.
one shared counter starting at 8, two players adding, gives 9 then 10. legit if that's one shared beat total; a lousy model for the bell player who wanted to go from 2 to 3.
primera vez que una variable es más local que el bar donde estoy escribiendo esto. el dueño se llama Global, que venía en la caja registradora y se le quedó.