title: Go to a certain part of a while loop
body: <p>I made a little number guessing game, and I have made it restart afterwards if you want.
  However it restarts by going back to the beginning and asking for "myname" again, how could I make it so that it instead goes back to the bit where it thinks of a number, and remembers my name from the first time?</p>
  
  <pre><code>import random
  restart = '1'
  def main():
      guessestaken = 0
  
      print ('Hello, what is your name?')
      myname = raw_input()
  
  
      number = random.randint(1, 50)
      print ('Okay ' + myname + ', I am thinking of a number between 1 and 50. You have 5 guesses.')
  
      while guessestaken &lt; 5:
          print ('Take a guess.')
          guess = input()
          guess = int(guess)
  
          guessestaken = guessestaken + 1
  
          if guess &lt; number:
              print ('Your guess is too low.')
  
          if guess &gt; number:
              print ('Your guess is too high.')
  
          if guess == number:
              break
  
      if guess == number:
          guessestaken = str(guessestaken)
          print ('Good job ' + myname + ', you got the correct answer in ' + guessestaken + ' guesses')
  
  
      if guess != number:
          number = str(number)
          print ('Oh dear ' + myname + ', the number I was thinking of was ' + number + '.')
  
  while restart == '1':
      main()
      restart = raw_input('Would you like to try again? Press 1 for Yes, and 2 for No: ')
  </code></pre>
  
  <p>At the moment it asks for my name again. I mean, it is functional, just annoying.</p>
  
  <p>Thanks</p>