python - Redefining a variable inside a loop -
i having problem getting 'undefined' error in code or, variable being incorrectly redefined. trying redefine variable inside loop each time loop executed. problem either (when variable defined outside loop) 'variable undefined' error, or variable not change and/or reset 0 when loop reinitialized. def game(): scoreplayer = 0 scoreai = 0 #if define here latter of 2 errors explained. number = random.randint(1, 6) print ("your score ", scoreplayer, ". opponent's score ", scoreai, ".") #this tells me referenced before defined if define outside loop. print (" ") print ("rolling...") print (" ") time.sleep(2) print ("you have rolled ", number, ".") print (" ") print ("player, hold (enter 'hold') or roll (enter 'roll')?") print (" ") decide = raw_input(" ") if decide == 'hold...