title: Using timer in python for a basic game
body: <p>I have to create this basic game for a high school project. I'm new to the timer in python. My code is as follows:</p>
  
  <pre><code>import random
  from threading import Timer
  
  score = -1
  directions = ["RIGHT", "LEFT", "UP", "DOWN"]
  accdirection=random.choice(directions)
  
  def timeOut():
      out_of_time = "yes"
      print("TESTING ")
  
  while accdirection:
       TimeLimit = 1   
       score = score + 1    
       accdirection=random.choice(directions)
       print(accdirection)
  
       out_of_time = "no" 
  
       t=Timer(TimeLimit,timeOut)
       t.start()
  
       fast = input()
  
       if out_of_time == "yes":
           accdirection = None
  
       if accdirection in directions:
           t.cancel()
  
  
           if accdirection == "RIGHT":
               if fast == "d":
                   accdirection = random.choice(directions)
               else:
                   accdirection = None
                   print("Oops, you clicked the wrong key.")
  
  
           elif accdirection == "LEFT":
               if fast == "a":
                   accdirection = random.choice(directions)
               else:
                   accdirection = None
                   print("Oops, you clicked the wrong key.")
  
  
           elif accdirection == "UP":
               if fast == "w":
                   accdirection = random.choice(directions)
               else:
                   accdirection = None
                   print("Oops, you clicked the wrong key.")
  
  
           elif accdirection == "DOWN":
  
               if fast == "s":
                   accdirection = random.choice(directions)
               else:
                   accdirection = None
                   print("Oops, you clicked the wrong key.")
  
       else:
           print("Oof, too slow!")
           accdirection = None
  
  
  
  
  
  print("Your score is:", score)
  </code></pre>
  
  <p>The function of the code is that python outputs a direction, and then the user has to input w, a, s or d. If they get the wrong key, the game is over and they have lost. This part works fine.
  When the time runs out it prints out "TESTING" which I have done simply to test if it even goes to the timeOut function. However, it feels like the value of out_of_time seems to always stay the same: "no" in this case. Therefore, the value for accdirection isn't able to reset to None to break the loop. I'm sorry if most of the code is just useless to my question. Please tell me how to fix this.</p>