error UnboundLocalError: local variable 'currentpl' referenced before assignment:
以下代码给出错误unboundlocalerror:分配前引用的本地变量"currentpl":
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | def play(num_sq, user_choice): drawStrip(num_sq) if user_choice == 0: currentpl = 1 elif user_choice == 1: currentpl = 2 while gameover(num_sq): if currentpl == 1: pick = getPlayerPick(num_sq) while not validPlay(pick, num_sq): pick = getPlayerPick(num_sq) makePlay(pick, player_col[currentpl]) if currentpl == 2: pick = computerSelection(num_sq) makePlay(pick, player_col[currentpl]) currentpl = togglePlayer(currentpl) if currentpl == 2: return"User" return"Computer" |
我怎么修这个?谢谢你的帮助!
当
如果
1 | if currentpl == 1: |
因为
这是不允许的-您需要允许在
1 2 | else: currentpl=10 |
在你上一个
另一种方法是确保在本节之前执行的代码中,