如何从函数内更新
player_points
的值?
我有一个具有此功能的模块。我想更改函数外部的变量
player_points
。我该怎么做?
此外,
player_points
只能从模块内部访问。
player_points=0 # how to update this var from within the function?
def player_draws_card():
drawn_card = random.choice(current_deck)
value = current_deck.pop(drawn_card)
player_hand[drawn_card] = value
player_points += value # this is the part that doesn't work
return drawn_card
您想在函数开始时声明“全局玩家点”。