I have a question??
Mike at DeleteThis.Geary.com
Tue Nov 11 20:43:15 CET 2003
> Ryan Silverwood wrote:
> > I want to write a python program which will calculate a person's net
> > 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%
> Oh come on, this is too easy:
> 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.
Sorry, Jim, those calculations are wrong. You'd better check the problem
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
More information about the Python-list