1 Reply Latest reply on Oct 6, 2009 11:06 PM by 390020

    Incomplete format error

      EDIT: never mind I figured out the problem~ it was an extra ":" inside the __main__... -.-!!
      But new problem! If I run the program and input the answers, it returns an error:
      Traceback (most recent call last):
      File "<string>", line 1, in <string>
      ValueError: incomplete format
      Does anyone know what this means?

      Original question

      Hi everyone, I'm a total beginner to Python, currently studying it in university.
      I'm almost done this assignment that asks me to create a program that accepts input from user on a few questions, then based on the answers calculate his or her total tax credit.
      Here is the full code:
      (Is it just me or is there no
       tags on a programming forum...???)
      #Tax credit calculator functions
      def dependant_amount(d_net_income):
          '''Return the deductible amount to be entered on line 5816 of the Ontario
          Tax form, based on float d_net_income, the dependant's net income.'''
          line_3 = max(0, 8108.00 - d_net_income)
          return min(7371.0, line_3)
      def medical_amount(d_net_income, med_expenses):
          '''Return the amount to be entered on line 5872: "Allowable medical
          expenses", of the Ontario Tax Form, based on float d_net_income,
          representing the taxpayer's dependant's net income, and float med_expenses,
          representing his or her medical expenses.'''
          line_2 = min(d_net_income * 0.03, 1965.0)
          return medical_expenses - line_2
      def age_amount(net_income):
          '''Return the amount to be entered on line 5808: "Age amount", of the
          Ontario Tax Form, based on float net_income, the taxpayer's net income. This
          credit applies only to persons born in 1943 or earlier.'''
          line_4 = max(0, net_income - 31554.0)
          line_6 = line_4 * 0.15
          age = max(0, 4239.0 - line_6)
          return age
      def infirm(d_net_income):
          '''Return the amount to be entered on line 5820: "Amount for infirm
          dependants age 18 or older", of the Ontario Tax Form, based on float 
          d_net_income, representing the taxpayer's dependant's net income.'''
          if 9908.0 - d_net_income > 4091.0:
              line_3 = 4091.0
              line_3 = max(0, 9908.0 - d_net_income)
          return line_3
      def political_amount(contribution):
          '''Return the amount to be entered on line 24: "Ontario political
          contribution tax credit", of the Ontario Tax Form, based on float
          contributions, representing the taxpayer's political contributions.'''
          if contribution <= 336.0:
              line_7 = contribution * 0.75
          elif 336.0 < contribution <= 1120.0:
              line_7 = ((contribution - 336.0) * 0.5) + 252.0
          elif 1120.0 < contribution <= 2548.0:
              line_7 = ((contribution - 1120.0) * 0.3333) + 644.0
              line_7 = 1120.0
          return line_7
      #Tax credit calculator
      if __name__ == "__main__:":
          #User-defined values of parameters of the functions defined earlier
          net_income = float(raw_input("Please enter your net income: "))
          d_net_income = float(raw_input("Please enter your dependant's net"
                                         " income: "))
          med_expenses = float(raw_input("Please enter your dependant's medical"
                                         " expenses: "))
          infirmity = raw_input("Is your dependant infirm (please enter 'yes' or"
                                "'no'): ")
          year_of_birth = float(raw_input("Please enter the year you were born (all"
                                          " four digits): "))
          contribution = float(raw_input("Please enter the amount of your political"
                                         " contributions: "))
          if infirmity == "yes":
              line_3 = True      
              line_3 = False
          if year_of_birth <= 1943:
              age = True
              age = False
          total_tax_credit = medical_amount(d_net_income, med_expenses) + \
                           age_amount(net_income) + infirm(d_net_income) + \
          print "Your Ontario Tax Credit is: $%" %total_tax_credit
      *In Python Shell after I click RUN*
      Type "help", "copyright", "credits" or "license" for more information.
      Evaluating tax_credit.py
      Basically the user is asked 6 questions, and each answer will have an effect on the variables operated in the functions defined in the first segment of the program. When I execute the program the questions written won't appear in Python Shell though...
      Thanks in advance for help!
      Edited by: user12005824 on 2009-10-6 下午3:57
      Edited by: user12005824 on 2009-10-6 下午3:59                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
        • 1. Re: Incomplete format error
          Do you realize this has nothing to do with oracle? You should subscribe to python list [1] next time for this kind of questions (and don't tell it's homework or else nobody will help you).
          Anyway, I think you're missing the output format [2]:
          print "Your Ontario Tax Credit is: $%f" % (total_tax_credit)

          [1] http://mail.python.org/mailman/listinfo/python-list
          [2] http://docs.python.org/library/stdtypes.html#string-formatting-operations