title: How to tell user how many attempts left in Python
body: <p>I am trying to make a random number game in python where the computer has to generate a number between 1 and 20 and you have to guess it. I have limited the amount of guesses to 6. How do I print how many guesses the user has left when they get a guess wrong? Here is my code:</p>
  
  <pre><code>import random
  
  attempts = 0
  
  name = input("What is your name? ")
  random = random.randint(1, 20)
  print(name + ",","I'm thinking of a number between 1 and 20, What is it?")
  
  while attempts &lt; 6:
      number = int(input("Type your guess: "))
      attempts = attempts + 1
      int(print(attempts,"attemps left")) #This is the code to tell the user how many attempts left
      if number &lt; random:
          print("Too low. Try something higher")
      if number &gt; random:
          print("Too high. Try something lower")
      if number == random:
          break
  if number == random:
      if attempts &lt;= 3:
          print("Well done,",name + "! It took you only",attempts,"attempts")
      if attempts &gt;= 4:
          print("Well done,",name + "! It took you",attempts,"attempts. Athough, next time try to get three attempts or lower")
  if number != random:
      print("Sorry. All your attempts have been used up. The number I was thinking of was",random)
  </code></pre>
  
  <p>Thanks, Any help is greatly appreciated!</p>