title: Want to create a personality test in python. How to do functions for this task?
body: <p>I have tried to make a file containing all of these questions but it went no good!</p>
  
  <p>question = open(filename.txt "r")</p>
  
  <p>This is what I have done:</p>
  
  <pre><code>#!/usr/bin/python
  #    questions.py
  
  
  
  questions1 = [("At a party do you", "interact with many, including strangers", "interact with a few, known  to you"),
      ("At parties do you", "Stay late, with increasing energy", "Leave early, with decreasing energy"),
      ("In your social groups do you", "Keep abreast of others happenings", "Get behind on the news"),
      ("Are you usually rather", "Quick to agree to a time", "Reluctant to agree to a time"),
      ("In company do you", "Start conversations", "Wait to be approached"),
      ("Does new interaction with others", "Stimulate and energize you", "Tax your reserves"),
      ("Do you prefer", "Many friends with brief contact", "A few friends with longer contact"),
      ("Do you", "Speak easily and at length with strangers", "Find little to say to strangers"),
      ("When the phone rings do you", "Quickly get to it first", "Hope someone else will answer"),
      ("At networking functions you are", "Easy to approach", "A little reserved")]
  
  
  counter_a, counter_b = 0, 0
  
  
  for question in questions1:
      question_string = "%s:\n\tA. %s\n\tB. %s\n[a/b]:  " % (question[0], question[1], question[2])
      answer = raw_input(question_string).lower()
      while answer not in ("a", "b"):
          print("Please choose A or B")
          answer = raw_input(question_string).lower()
      if answer == "a":
          counter_a += 1
      else:
          counter_b += 1
  
  #print "A total is %d" % counter_a
  #print "B total is %d" % counter_b
  
  
  if counter_a &gt; counter_b:
      print 'Your first personality code is: E'
  else:
      print 'Your first personality code is: I'
  
  ##############################################################################
  
  questions2 = [("Are you more", "Realistic", "Philosophically inclined "),
  ("Are you a more", "Sensible person", "Reflective person "),
  ("Are you usually more interested in", "Specifics", "Concepts "),
  ("Facts", "Speak for themselves", "Usually require interpretation "),
  ("Traditional common sense is", "Usually trustworthy", "often misleading "),
  ("Are you more frequently", "A practical sort of person", "An abstract sort of person "),
  ("Are you more drawn to", "Substantial information", "Credible assumptions "),
  ("Are you usually more interested in the", "Particular instance", "General case "),
  ("Do you prize more in yourself a", "Good sense of reality", "Good imagination "),
  ("Do you have more fun with", "Hands-on experience", "Blue-sky fantasy "),]
  
  
  counter2_a, counter2_b = 0, 0
  
  
  for question in questions2:
      question_string = "%s:\n\tA. %s\n\tB. %s\n[a/b]:  " % (question[0], question[1], question[2])
      answer = raw_input(question_string).lower()
      while answer not in ("a", "b"):
          print("Please choose A or B")
          answer = raw_input(question_string).lower()
      if answer == "a":
          counter2_a += 1
      else:
          counter2_b += 1
  
  #print "A total is %d" % counter2_a
  #print "B total is %d" % counter2_b
  
  
  
  ##############################################################################
  
  questions3 = [("Are you usually more", "Fair minded", "Kind hearted"),
  ("Is it more natural to be", "Fair to others", "Nice to others"),
  ("Are you more naturally", "Impartial", "Compassionate"),
  ("Are you inclined to be more", "Cool headed", "Warm hearted"),
  ("Are you usually more", "Tough minded", "Tender hearted"),
  ("Which is more satisfying", "To discuss an issue throughly", "To arrive at agreement on an issue"),
  ("Are you more comfortable when you are", "Objective", "Personal"),
  ("Are you typically more a person of", "Clear reason", "Strong feeling"),
  ("In judging are you usually more", "Neutral", "Charitable"),
  ("Are you usually more", "Unbiased", "compassionate")]
  
  counter3_a, counter3_b = 0, 0
  
  
  for question in questions3:
      question_string = "%s:\n\tA. %s\n\tB. %s\n[a/b]:  " % (question[0], question[1], question[2])
      answer = raw_input(question_string).lower()
      while answer not in ("a", "b"):
          print("Please choose A or B")
          answer = raw_input(question_string).lower()
      if answer == "a":
          counter3_a += 1
      else:
          counter3_b += 1
  
  plus1a3 = counter3_a + counter2_a
  plus2b3 = counter3_b + counter2_b
  
  #print "A total is %d" % plus1a3
  #print "B total is %d" % plus2b3
  
  if plus1a3 &gt; plus2b3:
      print 'Your second personality code is: S'
  else:
      print 'Your second personality code is: N'
  
  ##############################################################################
  
  questions4 = [("Do you tend to be more", "Dispassionate", "Sympathetic"),
  ("In first approaching others are you more", "Impersonal and detached", "Personal and engaging"),
  ("In judging are you more likely to be", "Impersonal", "Sentimental"),
  ("Would you rather be", "More just than merciful", "More merciful than just"),
  ("Are you usually more", "Tough minded", "Tender hearted"),
  ("Which rules you more", "Your head", "Your heart"),
  ("Do you value in yourself more that you are", "Unwavering", "Devoted"),
  ("Are you inclined more to be", "Fair-minded", "Sympathetic"),
  ("Are you convinced by?", "Evidence", "Someone you trust"),
  ("Are you typically more", "Just than lenient", "Lenient than just")]
  
  counter4_a, counter4_b = 0, 0
  
  
  for question in questions4:
      question_string = "%s:\n\tA. %s\n\tB. %s\n[a/b]:  " % (question[0], question[1], question[2])
      answer = raw_input(question_string).lower()
      while answer not in ("a", "b"):
          print("Please choose A or B")
          answer = raw_input(question_string).lower()
      if answer == "a":
          counter4_a += 1
      else:
          counter4_b += 1
  
  plus1a4 = counter4_a + counter3_a
  plus2b4 = counter4_b + counter3_b
  
  #print "A total is %d" % plus1a4
  #print "B total is %d" % plus2b4
  
  
  ##############################################################################
  
  questions5 = [("Do you prefer to work", "To deadlines", "Just whenever"),
  ("Are you usually more", "Punctual", "Leisurely"),
  ("Do you usually", "Settle things", "Keep options open"),
  ("Are you more comfortable", "Setting a schedule", "Putting things off"),
  ("Are you more prone to keep things", "well organized", "Open-ended"),
  ("Are you more comfortable with work", "Contracted", "Done on a casual basis"),
  ("Are you more comfortable with", "Final statements", "Tentative statements"),
  ("Is it preferable mostly to", "Make sure things are arranged", "Just let things happen"),
  ("Do you prefer?", "Getting something done", "Having the option to go back"),
  ("Is it more like you to", "Make snap judgements", "Delay making judgements")]
  
  counter5_a, counter5_b = 0, 0
  
  
  for question in questions5:
      question_string = "%s:\n\tA. %s\n\tB. %s\n[a/b]:  " % (question[0], question[1], question[2])
      answer = raw_input(question_string).lower()
      while answer not in ("a", "b"):
          print("Please choose A or B")
          answer = raw_input(question_string).lower()
      if answer == "a":
          counter5_a += 1
      else:
          counter5_b += 1
  
  plus1a5 = counter5_a + counter4_a
  plus2b5 = counter5_b + counter4_b
  
  #print "A total is %d" % plus1a5
  #print "B total is %d" % plus2b5
  
  if plus1a5 &gt; plus2b5:
      print 'Your third personality code is: T'
  else:
      print 'Your third personality code is: F'
  
  ##############################################################################
  
  questions6 = [("Do you tend to choose", "Rather carefully", "Somewhat impulsively"),
  ("Does it bother you more having things", "Incomplete", "Completed"),
  ("Are you usually rather", "Quick to agree to a time", "Reluctant to agree to a time"),
  ("Are you more comfortable with", "Written agreements", "Handshake agreements"),
  ("Do you put more value on the", "Definite", "Variable"),
  ("Do you prefer things to be", "Neat and orderly", "Optional"),
  ("Are you more comfortable", "After a decision", "Before a decision"),
  ("Is it your way more to", "Get things settled", "Put off settlement"),
  ("Do you prefer to?", "Set things up perfectly", "Allow things to come together"),
  ("Do you tend to be more", "Deliberate than spontaneous", "Spontaneous than deliberate")]
  
  counter6_a, counter6_b = 0, 0
  
  
  for question in questions6:
      question_string = "%s:\n\tA. %s\n\tB. %s\n[a/b]:  " % (question[0], question[1], question[2])
      answer = raw_input(question_string).lower()
      while answer not in ("a", "b"):
          print("Please choose A or B")
          answer = raw_input(question_string).lower()
      if answer == "a":
          counter6_a += 1
      else:
          counter6_b += 1
  
  plus1a6 = counter6_a + counter5_a
  plus2b6 = counter6_b + counter5_b
  
  #print "A total is %d" % plus1a6
  #print "B total is %d" % plus2b6
  
  
  if plus1a6 &gt; plus2b6:
      print 'Your fourth personality code is: J'
  else:
      print 'Your fourth personality code is: P'
  
  
  ####################################################################
  </code></pre>
  
  <p>I am new in terms of programming and apologize in advance if my question is vague!</p>
  
  <p>Short of what I want to do,
  I want to do a personality test based on Myers-Briggs Type Indicator</p>
  
  <p>I need to ask
  - Set about 70 questions with A or B options
  - I want to make this as easy as possible</p>
  
  <p>I pasted the code I have started with. - I understand that I am way off</p>
  
  <p>Thanks in advance for your help!</p>
  
  <pre><code>counterA = 0
  counterB = 0
  
  question = raw_input('At a party do you? \n A. Interact with many, includingstrangers \n B.            Interact with a few, known to you. \n ')
  print ''
  question = raw_input('At a party do you? \n A. Interact with many, includingstrangers \n B. Interact with a few, known to you. \n ')
  
  
  def question_x(x):
      raw_input('')
  
  question_x('')    
  
  def answer(x):
      if question == 'a' or question == 'A':
          counterB = counterB + 1
      else:
          counterB = counterB + 1 
  
  print counterA
  print counterB
  
  #if q1 == 'a' or q1 == 'A':
  #    counterA = counterA + 1
  #else:
  #    counterB = counterB + 1
  
  ############################################## 
  
  #if q2 == 'a' or q2 == 'A':
  #   counterA = counterA + 1
  #else:
  #    counterB = counterB + 1
  
  #print counterA
  #print counterB
  </code></pre>