次のコードは、さまざまな人が辞書を読んで所得税を計算し、税金を辞書に返すコードで、あるクイズの答えとして私が書きました。国 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