title: Storing a score in Python
body: <p>So far I have made a short game in which you have to guess the area of the shape in question. Only the triangle works so far and the correct answer is B for testing.</p>
  
  <p>I am trying to store the user's progress by putting it into a text file, but when I call a function to update the score, it overwrites the file so the score is removed! How can I get around this, and if I can't is there another way of doing this, because I want the user to be able to go from level to level?</p>
  
  <p>My code:</p>
  
  <pre><code>User_Points = '0'
  
  def LoginScreen():
      print("Welcome to Area Trainer")
      print("Please enter the username for your account")
      global user_name
      user_name = str(input())
      save = open(user_name + '.txt', 'w')
      save.write(str(User_Points))
  
  
      PasswordCheck= True
      while PasswordCheck:
          user_password = input("Type in your password: ")
          if len(user_password) &lt; 8:
              print("Your password must be 8 characters long")
          elif not any(i.isdigit() for i in user_password):
              print("You need a number in your password")
          elif not any(i.isupper() for i in user_password):
              print("You need a capital letter in your password")
          elif not any(i.islower() for i in user_password):
              print("You need a lowercase letter in your password")
          else:
              PasswordCheck = False
  
  
  def MenuTriangle():
      global User_Points
      User_Points = ''
      print('''Here is a triangle with a height of 12 cm and a width of 29 cm
      /\     |                *Not to scale.
     /  \    |
    /    \   | 12 cm
   /      \  |
   &lt;-------&gt;
      29 cm
      You must find out the area and select the correct answer from these options''')
      print('''A) 175
          B) 174
          C) 2000
          D) 199
  
             ''')
      user_input = input().upper()
  
      if user_input == "A":
              print("I'm sorry this is incorrect, but you still have a chance to get 1 point!")
              MenuTriangle2()
  
      elif user_input == "C":
              print("I'm sorry this is incorrect, but you still have a chance to get 1 point!")
              MenuTriangle2()
  
      elif user_input == "D":
              print("I'm sorry this is incorrect, but you still have a chance to get 1 point!")
              MenuTriangle2()
  
      elif user_input == "B":
              print("Congratulations! You got it right; someone's a smart cookie. Here have two points!")
              reading = open(user_name + '.txt')
              score = reading.read()
              score = score + '2'
              print("Your score is", score)
              save = open(user_name + '.txt', 'a')
              save.write(str(score))
              MenuStart()
  
  def MenuStart():
  
      print("Welcome to the mathematical area game!")
      print("In this game you will be required to calculate the area of multiple shapes.")
      print("To do this you must know how to calculate the area of different shapes with increasing difficulty.")
      print('''Please select a shape you want to play,
      A) Triangle
      B) Square
      C) Circle''')
      user_input = input().upper()
  
      if user_input == "A":
          print("You have chosen to calculate the area of a triangle!")
          MenuTriangle()
  
      elif user_input == "B":
          print("You have chosen to calculate the area of a square!")
          MenuSquare()
  
      elif user_input == "C":
          print("You have chosen the calculate the area of a circle!")
          MenuCircle()
  
      else:
          print("Oops! I didn't understand that &gt;:")
          MenuStart()
  
  
  LoginScreen()
  MenuStart()
  </code></pre>