title: How do you write a menu driven python programme
body: <p>Here's the question: </p>
  
  <p>Write a menu-driven Python program which includes the following;</p>
  
  <ul>
  <li>A function which takes a file name from the user and creates a file of the same name. The function should then use a while loop to process the file and allow the user to input a number of integers which are to be written to the file.</li>
  <li>A function which uses a <code>for</code> loop to read the contents of the file and outputs them to the screen.</li>
  <li>A function to append a number of integers to the File.</li>
  <li>A function which calculates the total of the numbers contained in the file and prints the
  answer to the screen</li>
  </ul>
  
  <p>Here's the code I've done so far, I just need help finishing it off:</p>
  
  <pre><code>def main():
      filename = input("Welcom, please enter file name:\t")
      menu()
      choice= int(input("Enter menu choice:\t"))
  
      while choice != 5:
          #get file choice from user
          if choice == 1:
              #create file
              create(filename)
          elif choice == 2:
              #read file
              read(filename)
          elif choice == 3:
              #append file
              append(filename)
          elif choice == 4:
              #get total
              get_total(filename)
  
          choice = int(input("Enter menu choice:\t"))
  
      print("\nApplication Complete")
  
  def menu():
  
      #user chooses a number from list
      print("Choose a number to continue:\t\n\
      Select 1 to create a file\n\
      Select 2 to read a file\n\
      Select 3 to append to a file\n\
      Select 4 to calculate the total of a file\n\
      Select 5 to exit programme")
  
  def create(filename):
  
      #open file name
      outfile = open(filename,"w")
      again = "y"
  
      while again == "y":
  
          try:
              num = int(input("Input number:\t")
              outfile.write(str(num)+"\n")
              #asks user whether they want to continue or not
              again = input("Enter y to continue:\t")
  
          except ValueError:
                        print("An error occured,please enter an integer:\t")
  
          except:
                        print("An undetermined error occurred")
      #close file
      outfile.close()
  
  def read(filename):
  
      read(filename)
      print("\nReading File)
  
      try:
          infile = open(filename,"r")
  
          for line in infile:
  
          number = int(line)
          print(number)
  
      except IOError:
              print("An error occured trying to read")
              print("the file", filename)
  
      except:
              print("An undefined error occurred")
  
  def append(filename):
  
      append(filename)
  
      print("\nAppending to file")
  
      try:
          #create file object
          outfile = open(filename, "a")
          again = "y"
  
      while again == "y":
  
          try:
              num = int(input("input number to append to file:\t"))
              outfile.write(str(num)+"\n")
              again = input ("enter y to continue:\t")
  
          except ValueError:
                  print("an error occured please an integer")
          except:
                  print("an undefined error occured")
  
      except IOError:
              print("an error occurred trying to read")
              print("the file", filename)
  
      except:
              print("an undefined error occurred")
  
              infile.close()
  
  
  
  #call main
  main()
  </code></pre>
  
  <p>It keeps saying there's an invalid syntax up in the <code>create</code> function with  <code>outfile.write(str(num)+"\n")</code>. Also, could someone help me write a function that calculates the total of the numbers contained in the file and prints the answer to the screen please? I'm using python 3.3.2.</p>
  
  <p>Ok so I got the code working, I just need help with writing a function to calculate the total of the numbers contained in the file and print the answer to the screen to finish it if anyone wants to help please</p>