0

the following code which should calculate income tax for different people reading from a dictionary and returning their tax to a dictionary was written by me in answer to a certain quiz; Country X calculates tax for its citizens using a graduated scale rate as shown below:

Yearly Income: 0 - 1000

Tax Rate: 0%

Yearly Income: 1,001 - 10,000

Tax Rate: 10%

Yearly Income: 10,001 - 20,200

Tax Rate: 15%

Yearly Income: 20,201 - 30,750

Tax Rate: 20%

Yearly Income: 30,751 - 50,000

Tax Rate: 25%

Yearly Income: Over 50,000

Tax Rate: 30%

{

    tax = {}
    def calculate_tax(income):
      for key, value in income.items():
        if value <= 1000:
          income_tax = 0
          tax = {key : income_tax}
        elif value in range(1001,10000):
          tax1 = 0 
          tax2 = 0.1 * (value - 1000)
          income_tax = tax1 + tax2
          tax = {key : income_tax}
        elif value in range(10001,20200):
          tax1 = 0
          tax2 = 0.1 *9000
          tax3 = 0.15 * (value - 10000)
          income_tax = tax1+tax2+tax3
          tax = {key : income_tax}
        elif value in range(20201,30750):
          tax1 = 0
          tax2 = 0.1 * 9000
          tax3 = 0.15 * 10200
          tax4 = 0.20 * (value - 20200)
          income_tax = tax1+tax2+tax3+tax4
          tax = {key : income_tax}
        elif value in range(30751,50000):
          tax1 = 0
          tax2 = 0.1 * 9000
          tax3 = 0.15 * 10200
          tax4 = 0.20 * 10550
          tax5 = 0.25 * (value - 30750)
          income_tax = tax1+tax2+tax3+tax4+tax5
          tax = {key : income_tax}
        elif value > 50000:
          tax1 = 0
          tax2 = 0.1 * 9000
          tax3 = 0.15 * 10200
          tax4 = 0.20 * 10550
          tax5 = 0.25 * 19250
          tax6 = 0.3 * (value - 50000)
          income_tax = tax1+tax2+tax3+tax4+tax5+tax6
          tax = {key : income_tax}
      return tax
    income = {‘Alex’: 500, ‘James’: 20500,‘Kinuthia’: 70000}

}

Can someone help tell me what is wrong with my code?

The following is the error message i get. THERE IS AN ERROR/BUG IN YOUR CODE Results:

Traceback (most recent call last):
  File "python/nose2/bin/nose2", line 8, in 
    discover()
  File "/usr/local/lib/python2.7/dist-packages/nose2/main.py", line 300, in discover
    return main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/nose2/main.py", line 100, in __init__
    super(PluggableTestProgram, self).__init__(**kw)
  File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/local/lib/python2.7/dist-packages/nose2/main.py", line 133, in parseArgs
    self.createTests()
  File "/usr/local/lib/python2.7/dist-packages/nose2/main.py", line 258, in createTests
    self.testNames, self.module)
  File "/usr/local/lib/python2.7/dist-packages/nose2/loader.py", line 67, in loadTestsFromNames
    for name in event.names]
  File "/usr/local/lib/python2.7/dist-packages/nose2/loader.py", line 82, in loadTestsFromName
    result = self.session.hooks.loadTestsFromName(event)
  File "/usr/local/lib/python2.7/dist-packages/nose2/events.py", line 224, in __call__
    result = getattr(plugin, self.method)(event)
  File "/usr/local/lib/python2.7/dist-packages/nose2/plugins/loader/testclasses.py", line 119, in loadTestsFromName
    result = util.test_from_name(name, module)
  File "/usr/local/lib/python2.7/dist-packages/nose2/util.py", line 106, in test_from_name
    parent, obj = object_from_name(name, module)
  File "/usr/local/lib/python2.7/dist-packages/nose2/util.py", line 117, in object_from_name
    module = __import__('.'.join(parts_copy))
  File "/home/ubuntu/Applications/andelabs-server/tmp/56cefbb14fa1511500d5b3b6-57bc2762e713b01900df735c-test.py", line 4, in 
    from tmp.andelabs_56cefbb14fa1511500d5b3b6_57bc2762e713b01900df735c import *
  File "/home/ubuntu/Applications/andelabs-server/tmp/andelabs_56cefbb14fa1511500d5b3b6_57bc2762e713b01900df735c.py", line 43
SyntaxError: Non-ASCII character '\xe2' in file /home/ubuntu/Applications/andelabs-server/tmp/andelabs_56cefbb14fa1511500d5b3b6_57bc2762e713b01900df735c.py on line 43, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44

2 Answers2

0

You have a non ascii character in the code. Looking at it I'd say it's the quote marks you are using. Replace them with regular quote marks:

Note: If you want to use non ascii characters in a string or something you'll need to include the file encoding at the top but only do this if you need them

 # -*- coding: utf-8 -*-
FloatingKiwi
  • 4,408
  • 1
  • 17
  • 41
0

On this line in your code:

#income = {‘Alex’: 500, ‘James’: 20500,‘Kinuthia’: 70000}

Don't use back ticks, use normal quotation marks and remember this is Python, not MySQL database.

S.I.
  • 3,250
  • 12
  • 48
  • 77
kabaka
  • 16
  • 1