下面的代码应该计算从字典中阅读的不同人的所得税并将他们的税返还到字典中,这是我在回答某个测验时编写的;X 国使用如下所示的分级税率计算其公民的税收:
年收入:0 - 1000
税率:0%
年收入:1,001 - 10,000
税率:10%
年收入:10,001 - 20,200
税率:15%
年收入:20,201 - 30,750
税率:20%
年收入:30,751 - 50,000
税率:25%
年收入:超过50,000
税率: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}
}
有人可以帮我告诉我我的代码有什么问题吗?
以下是我收到的错误消息。您的代码结果中存在错误/错误:
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