473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Search Smarter - get the new eXact Search Bar for free!
http://www.exactsearchbar.com/
Jul 18 '05 #1
7 2671
Ryan Silverwood wrote:
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.
thanx

You're welcome

Bruno

Jul 18 '05 #2
rm
Ryan Silverwood wrote:
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

Jul 18 '05 #3
Ryan Silverwood wrote:
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

Jul 18 '05 #4
Jim
Ryan Silverwood wrote:
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
--
Registered Linux User #269187
http://counter.li.org
Jul 18 '05 #5
> Ryan Silverwood wrote:
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%

Jim wrote: 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
Jul 18 '05 #6
On Tue, 11 Nov 2003 07:06:26 -0500, Ryan Silverwood <ry***@mad.scientist.com> wrote:
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

--
"It's easier to find people online who openly support the KKK than
people who openly support the RIAA" -- comment on Wikipedia
(Email: <ze******@zen.co.ku>, but first subtract 275 and reverse
the last two letters).
Jul 18 '05 #7
ph***@invalid.email.address (phil hunt) wrote in message news:<sl******************@cabalamat.cabalamat.org >...
On Tue, 11 Nov 2003 07:06:26 -0500, Ryan Silverwood <ry***@mad.scientist.com> wrote:
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
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.