如何修复未绑定的本地错误?

时间:2017-12-09 19:39:21

标签: python python-3.x

错误 自我点+ = cardPoints UnboundLocalError:局部变量' selfpoints'在分配前引用

class userpoint_status:
     def __init__():
         selfpoints = 0
     def increase_points():
         self.points += cardPoints
         print("You have",selfpoints,"points")
         if selfpoints > 21:
                 lose_game() 

1 个答案:

答案 0 :(得分:0)

您的代码中出现了多次出现,您键入selfpoints而不是self.points。您需要将点放在那里,使其成为实例变量。鉴于cardPointslose_game是全局变量,您不会再有任何错误。