[Tutor] Tax Brand

Alan Gauld alan.gauld at btinternet.com
Wed Oct 9 01:19:12 CEST 2013


On 08/10/13 21:38, Thabile Rampa wrote:

> deductions. I have seemingly worked everything fine until the part where
> I am supposed to tell them what tax Band they are in (i.e 1,2,3 or 4).
> My code is like this:
>
> taxBAND = None
> GrossSalary = None
> costs = None
> taxdeducted =None
> netSalary = None

You don't really need these since you initialise everything below...
But thats not your problem.

> line ="-"*80
> name =""

> while not name:
>       name =raw_input("ENTER NAME HERE: ")
> while not costs:
>      costs =float(raw_input("enter costs here: "))
> while not GrossSalary:
>      GrossSalary= int(raw_input("enter your gross salary: "))

OK so far

> if (GrossSalary < 50000):
>      taxdeducted= 0.05*(GrossSalary -costs)
>      netSalary = GrossSalary - taxdeducted
>      while GrossSalary < 50000:

Here is a problem.
You already know the salary is less than 50000 since you tested it in 
the if statement. So now you create a loop that will always be true so 
it will loop forever.

>           print taxBAND == 1

And you compound that by trying to print the result of a
Boolean expression which will be either True or False.
I suspect you actually want to print(or store?) the
taxBAND (unusual capitalization BTW)

> elif (GrossSalary >= 50000 and GrossSalary < 150000):
>       taxdeducted = 0.1*(GrossSalary - costs)
>       netSalary = GrossSalary - taxdeducted

And here you make no attempt to set the taxBAND?

> print line
> print "\t\t BURS STATEMENT: ",name
> print line
> print "Gross", "\t Costs", "\t Tax BAND", "\tTax Deducted", "\t Net Salary"
> print
> GrossSalary,"\t",costs,"\t\b",taxBAND,"\t",taxdeducted,"\t\t",netSalary

Nice try but you'll find it easier to use the string format operation to 
create fixed length fields.
And that will still depend on your user having fixed space fonts.


> 1.
> Traceback (most recent call last):
> File "X:/xxx/Xxxx.py", line 30, in <module>
> taxBAND += 1
> TypeError: unsupported operand type (s) for +=: 'NoneType' and 'int'

Because you set taxBAND to None initially.
You probably just wanted to set taxBAND to 1 not add it.

> 2.
> Traceback (most recent call last):
> File "X:/xxx/Xxxx.py", line 30, in <module>
> taxBAND = I
> NameError: Name 'I' is not defined

And that's true too. You either wanted to set it to 1
or to 'I' (with quotes)

> (the first two errors were before i added the line "while GrossSalary <
> 50000:")

Probablty thats correct, but you want assdignment not equality test

ie
taxBAND = 1

> 3.
> Traceback (most recent call last):
> File "X:/xxx/Xxxx.py", line 31, in <module>
> taxBAND += 1
> TypeError: unsupported operand type (s) for +=: 'NoneType' and 'int'

See above

> 4.
> Traceback (most recent call last):
> File "X:/xxx/Xxxx.py", line 31, in <module>
> taxBAND = I
> NameError: Name 'I' is not defined

And again.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list