我在网上学习Python和需要提交一个解决方案,我已经尝试了本地我的代码和repl.it和代码运行,但在单元测试,然后在线平地机抛出一个错误:诠释不迭代错误
"THERE IS AN ERROR/BUG IN YOUR CODE
Results:
Internal Error: runTests aborted: TestOutcomeEvent(handled=False, test=, result=, outcome='error', exc_info=(, TypeError("'int' object is not iterable",),), reason=None, expected=False, shortLabel=None, longLabel=None) is not JSON serializable"
我的代码如下:
def calculate_tax(income2Tax):
zeroPercentRate = 0.0
tenPercentRate = 0.1
fifteenPercentRate = 0.15
twentyPercentRate = 0.20
twenty5PercentRate = 0.25
thirtyPercentRate = 0.30
ten = 9000
fifteen = 10200
twenty = 10550
twenty5 = 19250
taxedIncome = {}
rate = 0
for name in income2Tax:
if (income2Tax[name] <= 1000):
rate = 0
taxedIncome[name] = rate
elif (income2Tax[name] >= 1001) and (income2Tax[name] <= 10000):
rate = ((income2Tax[name] - 1000) * tenPercentRate)
taxedIncome[name] = rate
elif (income2Tax[name] >= 10001) and (income2Tax[name] <= 20200):
rate = (ten * tenPercentRate) + (income2Tax[name] - 10000) * fifteenPercentRate
taxedIncome[name] = rate
elif (income2Tax[name] >= 20201) and (income2Tax[name] <= 30750):
rate = (ten * tenPercentRate) + (fifteen * fifteenPercentRate) + (income2Tax[name] - 20200) * twentyPercentRate
taxedIncome[name] = rate
elif (income2Tax[name] >= 30751) and (income2Tax[name] <= 50000):
rate = (ten * tenPercentRate) + (fifteen * fifteenPercentRate) + (twenty * twentyPercentRate) + (income2Tax[name] -30750) * twenty5PercentRate
taxedIncome[name] = rate
elif (income2Tax[name] > 50000):
rate = (ten * tenPercentRate) + (fifteen * fifteenPercentRate) + (twenty * twentyPercentRate) + (twenty5 * twenty5PercentRate) + (income2Tax[name] - 50000) * thirtyPercentRate
taxedIncome[name] = rate
return taxedIncome
sampleData = {'bob': 500, 'bill': 20500, 'bale': 70000, 'bub': 8000, 'bit':19000}
print calculate_tax(sampleData)
我将不胜感激知道,如果有什么错我的代码。
你怎么不知道,如果你的代码的工作?您是否尝试过在本地进行测试?你是怎么写的? – jonrsharpe
代码在本地运行(ubuntu 16.10)并在repl.it编译器上运行,但在课程站点上运行时生成错误。 – driftavalii