I have a question??

R

Ryan Silverwood

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
http://www.mail.com/?sr=signup

Search Smarter - get the new eXact Search Bar for free!
http://www.exactsearchbar.com/
 
R

rm

Ryan said:
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


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
 
B

Bruno Desthuilliers

Ryan said:
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

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.
You're welcome

Bruno
 
A

Alex Martelli

Ryan said:
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%

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
 
J

Jim

Ryan said:
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

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
 
M

Michael Geary

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.

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
 
P

phil hunt

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%

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

def calcNetIncome(gross):
if youAreAskingUsenetToDoYourHomework:
taxRate = 100
net = gross * (100-taxRate)/100
return net
 
H

Hung Jung Lu

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%

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

def calcNetIncome(gross):
if youAreAskingUsenetToDoYourHomework:
taxRate = 100
net = gross * (100-taxRate)/100
return net

:)

Within integer precision,

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

Hung Jung
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top