[Tutor] 'int' object has no attribute 'items'
chidinma.ikebudu at yahoo.com
chidinma.ikebudu at yahoo.com
Sat Sep 3 17:45:17 EDT 2016
Hello,Am trying to solve a problem, but keep getting different errors.
Country X calculates tax for its citizens using a graduated scale rate as shown below:
- Yearly Income: 0 - 1000Tax Rate: 0%
- Yearly Income: 1,001 - 10,000Tax Rate: 10%
- Yearly Income: 10,001 - 20,200Tax Rate: 15%
- Yearly Income: 20,201 - 30,750Tax Rate: 20%
- Yearly Income: 30,751 - 50,000Tax Rate: 25%
- Yearly Income: Over 50,000Tax Rate: 30%
Am trying to write a Python function that will calculate tax rate.
def calculate_tax(dict_inp): result = {} if dict_inp == {}: result = "Please enter valid inputs" else: for k, v in dict_inp.items(): try: x = int(dict_inp[k]) except ValueError: print("That's not an int!") break if(x): if x > 50000: tax = ((x - 50000) * 0.3) + 4812.5 + 2110 + 1530 + 900 result[k] = tax elif x > 30750: tax = ((x - 30750) * 0.25) + 2110 + 1530 + 900 result[k] = tax elif x > 20200: tax = ((x - 20200) * 0.2) + 1530 + 900 result[k] = tax elif x > 10000: tax = ((x - 10000) * 0.15) + 900 result[k] = tax elif x > 1000: tax = ((x - 1000) * 0.1) result[k] = tax else: tax = 0 result[k] = tax else: print("Yearly income is not an integer") return result dict_inp = {'Alex': 500,'James': 20500,'Kinuthia': 70000}#dict_inp = {200: 1500,300: 20500,400: 70000}print(calculate_tax(dict_inp))
But I get the result:
THERE IS AN ERROR/BUG IN YOUR CODE
Results: Internal Error: runTests aborted: TestOutcomeEvent(handled=False, test=, result=, outcome='error', exc_info=(, AttributeError("'int' object has no attribute 'items'",), ), reason=None, expected=False, shortLabel=None, longLabel=None) is not JSON serializable{'James': 2490.0, 'Alex': 0, 'Kinuthia': 15352.5}
But when i take away the .items(), i get:
for k, v in dict_inp:
ValueError: too many values to unpack
Please I need help.I am using windows 10, python 3.5.2, Thanks
More information about the Tutor
mailing list