I have a question??

rm rm at rm.net
Tue Nov 11 09:35:46 EST 2003


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





More information about the Python-list mailing list