我正试图制作一个文字,列出地方变量,将其从功能中引出,并将操纵价值退回到主要范围(或无论它所呼吁的是什么;我是新到沙里)。
我认为,我已经简化了我的法典,以显示我努力完成的工作的最基本条件,即从单元进口一个地方,成为功能区。
我通过使用<条码>Globals,而这是最佳解决办法。
chambersinreactor = 0;
cardsdiscarded = 0;
def find_chamber_discard():
"""Find chambers and discard in row (reads each player slot)"""
chambersinreactor = 0; # Resets the variable, not what I want
cardsdiscarded = 0; # Resets the variable, not what I want
chambersinreactor += 1
cardsdiscarded += 1
return # Don t know what to put here
find_chamber_discard()
print chambersinreactor # prints as 0, should be 1
print cardsdiscarded # prints as 0, should be 1