[Tutor] 'int' object has no attribute 'items'

Peter Otten __peter__ at web.de
Sun Sep 4 05:11:02 EDT 2016


Chidinma via Tutor wrote:

> 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.

Perhaps you misunderstood the task and you were asked to write a simpler 
function that takes a value and calculates the tax. For example, in a 
country with a rate of 50% for everyone the solution would look like this...

# expected?
def caculate_tax(income):
    return 0.5 * income

...but you wrote something similar to

def calculate_tax(payer_income_pairs):
    return {
        payer: income * 0.5 
        for payer, income in payer_income_pairs.items()}

> 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: 

Awful. Please change your configuration to preserve newlines before posting 
more code.



More information about the Tutor mailing list