我在做一个小游戏。当玩家给出快速答案时,我想给他们积分。 所以,我做了10秒的倒计时。 但是当我尝试确定剩余秒数时,出现错误。
代码:
#variable: 10 seconds
Countdown = 10
#function to count down seconds
def Timer(Countdown):
while Countdown:
time.sleep(1)
Countdown -= 1
#variable to see how many seconds remain (this is inside another function, when the player hits the button)
Time = Countdown
我收到错误:UnboundLocalError: cannot access variable 'Countdown' where it is not associated with a value.