title: How to run a background timer in Python
body: <p>I'm currently making a math game where the user has 60 seconds to answer as many questions as possible. As of now, I have everything working except for the timer which should either count down to 0 or count up to 60 then stop the game. Right now, I have the timer set to time.clock() to count up to 60 and while the timer is less than that, the game will continue to run. For some reason however, the time.clock() isn't working as I expect it to. I also tried running two while loops at the same time which didn't work either. Anyone able to help me out here? Simply looking for a way to have a timer run in the background.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    score = 0
      timer = time.clock()
      lives = 3
  
      while timer &lt; 60 and lives &gt; 0:
          if score &gt;= 25:
              x = random.randint(-100,100)
              y = random.randint(-100,100)
              answer = int(raw_input("What is %d + %d? " % (x,y)))
              if answer == x + y:
                  print "Correct!"
                  score += 1
              else:
                  print "Wrong!"
                  lives -= 1
          elif score &gt;= 20:
              x = random.randint(-75,75)
              y = random.randint(-75,75)
              answer = int(raw_input("What is %d + %d? " % (x,y)))
              if answer == x + y:
                  print "Correct!"
                  score += 1
              else:
                  print "Wrong!"
                  lives -= 1
          elif score &gt;= 15:
              x = random.randint(-50,50)
              y = random.randint(-50,50)
              answer = int(raw_input("What is %d + %d? " % (x,y)))
              if answer == x + y:
                  print "Correct!"
                  score += 1
              else:
                  print "Wrong!"
                  lives -= 1
          elif score &gt;= 10:
              x = random.randint(-25,25)
              y = random.randint(-25,25)
              answer = int(raw_input("What is %d + %d? " % (x,y)))
              if answer == x + y:
                  print "Correct!"
                  score += 1
              else:
                  print "Wrong!"
                  lives -= 1
          elif score &gt;= 5:
              x = random.randint(-10,10)
              y = random.randint(-10,10)
              answer = int(raw_input("What is %d + %d? " % (x,y)))
              if answer == x + y:
                  print "Correct!"
                  score += 1
              else:
                  print "Wrong!"
                  lives -= 1
          elif score &gt;= 0:
              x = random.randint(-5,5)
              y = random.randint(-5,5)
              answer = int(raw_input("What is %d + %d? " % (x,y)))
              if answer == x + y:
                  print "Correct!"
                  score += 1
              else:
                  print "Wrong!"
                  lives -= 1
      if lives == 0:
          print "Oh no! You ran out of lives! Your score was %d." % score
      elif timer == 60:
          print "Time's up! Your score is %d." % score
  else:
      print "Goodbye!"
  </code></pre>