I have a question??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan Silverwood

    I have a question??

    I want to write a python program which will calculate a person's net annual income after tax, given the following rules:
    *The first 1500 is tax free
    *any amount earned over £1500 and upto £35000 is taxed at 30%
    *and amount earned over £35000 is taxed at 45%


    if anyone could help it would be much appreciated

    thanx
    --
    _______________ _______________ _______________ _____________
    Sign-up for your own personalized E-mail at Mail.com
    The right email address for you ✔ Secure ✔ 100+ domain names ✔ Up to 10 mail addresses ✔ Sync across devices ✔ 65GB email storage ✔ Sign up today!


    Search Smarter - get the new eXact Search Bar for free!



  • Bruno Desthuilliers

    #2
    Re: I have a question??

    Ryan Silverwood wrote:[color=blue]
    > I want to write a python program which will calculate a person's net annual income after tax, given the following rules:
    > *The first 1500 is tax free
    > *any amount earned over £1500 and upto £35000 is taxed at 30%
    > *and amount earned over £35000 is taxed at 45%
    >
    >
    > if anyone could help it would be much appreciated[/color]

    1/ Do it on paper,
    2/ analyse how you did it,
    3/ try to abstract the rules,
    4/ write functions implementing those rules,
    5/ write test testing the functions
    6/ write a program using those functions,

    and you're done.

    You may eventually swap 4 and 5 (write the tests first)

    If you get stuck anywhere between 4 and 6, or want some review,
    criticism, advices about your code, feel free to post here with the
    relevant code.
    [color=blue]
    > thanx[/color]
    You're welcome

    Bruno

    Comment

    • rm

      #3
      Re: I have a question??

      Ryan Silverwood wrote:[color=blue]
      > I want to write a python program which will calculate a person's net annual income after tax, given the following rules:
      > *The first 1500 is tax free
      > *any amount earned over £1500 and upto £35000 is taxed at 30%
      > *and amount earned over £35000 is taxed at 45%
      >
      >
      > if anyone could help it would be much appreciated
      >
      > thanx[/color]


      I didn't test it, and it's only one solution.
      To get a better grade though, you should probably clean it up a bit :-)

      def calctax( earnings ) :
      tax = 0.0
      if earnings >= 35000 :
      tax += 0.45 * ( earnings - 35000 )
      if earnings >= 15000 :
      tax += 0.30 * ( max( min( earnings
      , 35000
      )
      , 15000
      )
      - 15000
      )
      return tax

      def netincome( earnings ) :
      return earnings - calctax( earnings )

      bye,
      rm

      Comment

      • Alex Martelli

        #4
        Re: I have a question??

        Ryan Silverwood wrote:
        [color=blue]
        > I want to write a python program which will calculate a person's net
        > annual income after tax, given the following rules: *The first 1500 is tax
        > free *any amount earned over £1500 and upto £35000 is taxed at 30%
        > *and amount earned over £35000 is taxed at 45%[/color]

        It's interesting that somebody else asked _exactly_ this question,
        numbers and all, on Sunday. Starting to look like some teacher (in
        the UK, pehraps, given the mention of points) has given a Python
        assignment, maybe...?


        Alex

        Comment

        • Jim

          #5
          Re: I have a question??

          Ryan Silverwood wrote:
          [color=blue]
          > I want to write a python program which will calculate a person's net annual
          > income after tax, given the following rules: *The first 1500 is tax free
          > *any amount earned over £1500 and upto £35000 is taxed at 30%
          > *and amount earned over £35000 is taxed at 45%
          >
          >
          > if anyone could help it would be much appreciated
          >
          > thanx[/color]

          Oh come on, this is too easy:

          X=INCOME
          IF X<=1500 THEN TAX=0
          IF X>1500 AND X<=35000 THEN TAX=X*.30
          IF X>35000 THEN TAX=X*.45

          I'll let you figure out how to do this in Python.

          Jim
          --
          Registered Linux User #269187



          Comment

          • Michael Geary

            #6
            Re: I have a question??

            > Ryan Silverwood wrote:[color=blue][color=green]
            > > I want to write a python program which will calculate a person's net[/color][/color]
            annual[color=blue][color=green]
            > > income after tax, given the following rules: *The first 1500 is tax free
            > > *any amount earned over £1500 and upto £35000 is taxed at 30%
            > > *and amount earned over £35000 is taxed at 45%[/color][/color]

            Jim wrote:[color=blue]
            > Oh come on, this is too easy:
            >
            > X=INCOME
            > IF X<=1500 THEN TAX=0
            > IF X>1500 AND X<=35000 THEN TAX=X*.30
            > IF X>35000 THEN TAX=X*.45
            >
            > I'll let you figure out how to do this in Python.[/color]

            Sorry, Jim, those calculations are wrong. You'd better check the problem
            description again.

            Ryan, here is a suggestion for you. Don't write the tax brackets directly
            into the program code as in the couple of examples that have been posted.
            Instead, make a separate table of tax brackets, e.g.:

            # List of tax brackets as ( startingIncome, percentTax )
            brackets = [
            ( 1500, .30 ),
            ( 35000, .45 ),
            ]

            Now write a function that loops over the list of tax brackets, calculating
            and accumulating the tax for each bracket.

            I actually wrote that code just for fun, but then I started to think to
            myself, "This sure sounds like a homework problem." Alex's reply confirmed
            that--so I don't think I'll post the complete code, but if you'd like to try
            your hand at it I'll be happy to give you some feedback on your code.

            For extra credit, give two reasons why it's better to put the tax brackets
            in a separate table instead of coding the numbers directly in your
            calculations.

            -Mike


            Comment

            • phil hunt

              #7
              Re: I have a question??

              On Tue, 11 Nov 2003 07:06:26 -0500, Ryan Silverwood <ryans@mad.scie ntist.com> wrote:[color=blue]
              >I want to write a python program which will calculate a person's net annual income after tax, given the following rules:
              >*The first 1500 is tax free
              >*any amount earned over £1500 and upto £35000 is taxed at 30%
              >*and amount earned over £35000 is taxed at 45%[/color]

              infinity = 999999
              taxRates = [ [1500, 0], [35000-1500, 30], [infinity, 45] ]

              def calcNetIncome(g ross):
              if youAreAskingUse netToDoYourHome work:
              taxRate = 100
              net = gross * (100-taxRate)/100
              return net

              --
              "It's easier to find people online who openly support the KKK than
              people who openly support the RIAA" -- comment on Wikipedia
              (Email: <zen20000@zen.c o.ku>, but first subtract 275 and reverse
              the last two letters).


              Comment

              • Hung Jung Lu

                #8
                Re: I have a question??

                philh@invalid.e mail.address (phil hunt) wrote in message news:<slrnbr3ag u.hvk.philh@cab alamat.cabalama t.org>...[color=blue]
                > On Tue, 11 Nov 2003 07:06:26 -0500, Ryan Silverwood <ryans@mad.scie ntist.com> wrote:[color=green]
                > >I want to write a python program which will calculate a person's net annual income after tax, given the following rules:
                > >*The first 1500 is tax free
                > >*any amount earned over £1500 and upto £35000 is taxed at 30%
                > >*and amount earned over £35000 is taxed at 45%[/color]
                >
                > infinity = 999999
                > taxRates = [ [1500, 0], [35000-1500, 30], [infinity, 45] ]
                >
                > def calcNetIncome(g ross):
                > if youAreAskingUse netToDoYourHome work:
                > taxRate = 100
                > net = gross * (100-taxRate)/100
                > return net[/color]

                :)

                Within integer precision,

                bracket = round(gross)*[1,]
                net = gross - 0.3*len(bracket[1500:35000]) - 0.45*len(bracke t[35000:])

                Hung Jung

                Comment

                Working...