title: writing a text file on python
body: <pre><code>import time
  def mainmenu ():
      print ("1.set values")
      print ("2. run formula")
      print ("3. export formula results")
      maininput = int(input("Enter: "))
      if maininput == 1:
          set_values ()
      elif maininput == 2:
          formula ()
      elif maininput == 3:
          export ()
  
  def set_values ():
      set_values.first = int(input("Value 1 between 1 and 10"))
      while 1&lt; set_values.first &lt;10:
          set_values.second = int(input("Value 2 between 1 and 10"))
          while 1&lt; set_values.second &lt;10:
              mainmenu ()
      else:
          print ("That is not a valid value")
          return set_values ()
  
  def formula ():
      part_1 = set_values.first + set_values.second
      print ("Value 1 + value 2 =",part_1)
      time.sleep(2)
      part_2 = part_1 * 5
      print ("Value 1 + value 2 x 5 =",part_2)
      time.sleep(2)
  def export ():
      print ()
  
  mainmenu ()
  </code></pre>
  
  <p>What code would I use in def export to replace print () so the data printed in formula is written to a text file.
  Before the data is written the user should be asked to enter a file name and the code should check if a file with the same name exists and if so ask the user if it should be overwritten. If the user chooses not to overwrite the file they should be returned to the part where they enter the file name. </p>