title: How do i add a timer that counts down and when it runs out it restarts my program
body: <p>I'm a very new beginner coder and I don't know much yet. I am trying to create a guessing game, and I want to add a timer to the program.
  The way the timer would work would be that I set up a set amount of time i.e. 60 seconds and once the time has run out the program would stop and basically be like &quot;sorry you ran out of time. Would you like to try again?&quot;</p>
  <p>I've already searched for some videos on YouTube and on Stackoverflow but I either don't understand it or I'm unable to do it.</p>
  <p><a href="https://www.youtube.com/watch?v=Mp6YMt8MSAU" rel="nofollow noreferrer">https://www.youtube.com/watch?v=Mp6YMt8MSAU</a></p>
  <p>I've watched this video like 4 times and still have no clue how to do it. So if anyone is willing to explain to me/show me how to add time that would be much appreciated</p>
  <pre class="lang-py prettyprint-override"><code>def main():
      import random
      n = random.randint(1, 99)
      chances = 5
      guess = int(input(&quot;Player 2 please enter an integer from 1 to 99, you have 5 chances: &quot; ))
      while n != &quot;guess&quot;:
          chances -=1
          if chances ==0:
              print(&quot;out of chances, it is now player 2's turn to play. The number was&quot;, n)
              break
          if guess &lt; n:
              print(&quot;guess is low you have&quot;,chances,&quot;chances left&quot;)
              guess = int(input(&quot;Enter an integer from 1 to 99: &quot;))
          elif guess &gt; n:
              print (&quot;guess is high you have&quot;,chances, &quot;chances left&quot;)
              guess = int(input(&quot;Enter an integer from 1 to 99: &quot;))
          else:
              print(&quot;you guessed it and have&quot;, chances, &quot;chances left&quot;)
              break
              
          import random
      n1 = random.randint(1, 99)
      chances1 = 0
      guess1 = int(input(&quot;Player 2 please enter an integer from 1 to 99, you have 5 chances: &quot;))
      while n1 != &quot;guess&quot;:
          chances1 +=1
          if chances1 ==5:
              print(&quot;out of chances, the number was&quot;, n1)
              break
          if guess1 &lt; n1:
              print(&quot;guess is low you have&quot;,chances1,&quot;chances left&quot;)
              guess1 = int(input(&quot;Enter an integer from 1 to 99: &quot;))
          elif guess &gt; n1:
              print (&quot;guess is high you have&quot;,chances1, &quot;chances left&quot;)
              guess1 = int(input(&quot;Enter an integer from 1 to 99: &quot;))
          else:
              print(&quot;you guessed it and have&quot;, chances1, &quot;chances left&quot;)
              break
      retry=input(&quot;would you like to play again? (please choose either 'yes' or 'no' )&quot;)
      if retry == &quot;yes&quot;:
          main()
      elif retry == &quot;no&quot;:
          print(&quot;Okay. have a nice day! :D &quot;)
      else:
          print(&quot;Invalid input&quot;)
  main()
  </code></pre>
  <p>This is my code. Any feedback would be appreciated.</p>