python calculation of tax using my format below

0 Akhator Itua · September 3, 2016
The code below contains my code  in calculating the salary tax of every individual between the ranges specified below. but when i run the program it gives me a an error "INT CANNOT ITERATE". can someone pls tell me whst the problem is?

   def calculate_tax(data):
   app = {}
        for name in data:
            if data[name] >=0 and data[name] <= 1000:
               value = data[name] - 0
              app[name] = value * 0 
           if data[name] >=1001 and data[name] <=10000:
               tax1 = 1000 * 0
               value2 = data[name] - 1000
               tax2 = value2 * 0.1
               app[name] =  tax1 + tax2
           if data[name] >=10001 and data[name] <=20200:
               tax1 = 1000 * 0
               value2 = 10000 - 1000
               tax2 = value2 * 0.1
                value3 = data[name] - 10000
               tax3 = value3 * 0.15
               app[name] =  tax1 + tax2 + tax3
          if data[name] >=20201 and data[name] <=30750:
               tax1 = 1000 * 0
               value2 = 10000 - 1000
               tax2 = value2 * 0.1
               value3 = 20200 - 10000
               tax3 = value3 * 0.15
               value4 = data[name] - 20200
               tax4 = value4 * 0.2
               app[name]= tax1 + tax2 + tax3 + tax4
          if data[name] >=30751 and data[name] <=50000:
               tax1 = 1000 * 0
               value2 = 10000 - 1000
               tax2 = value2 * 0.1
               value3 = 20200 - 10000
               tax3 = value3 * 0.15
               value4 = 30750 - 20200
               tax4 = value4 * 0.2
               value5 = data[name]- 30750
               tax5 = value5 * 0.25
               app[name] = tax1 + tax2 + tax3 + tax4 + tax5
          if data[name] > 50000:
               tax1 = 1000 * 0
               value2 = 10000 - 1000
               tax2 = value2 * 0.1
               value3 = 20200 - 10000
               tax3 = value3 * 0.15
               value4 = 30750 - 20200
               tax4 = value4 * 0.2
               value5 = 50000 - 30750
              tax5 = value5 * 0.25
              value6 = data[name] - 50000
              tax6 = value6 * 0.3
              app[name] = tax1 + tax2 + tax3 + tax4 + tax5 + tax6
     return app
print(calculate_tax({"Darey":500, "Itua":9000, "Dayo":20500, "Akhator":700000}))

Post a Reply

Replies

Oldest  Newest  Rating
0 Ray Kerr · September 10, 2016
output

{'Darey': 0, 'Itua': 800.0, 'Dayo': 2490.0}
'{Dayo': 2490.0, 'Itua': 800.0, 'Darey': -5497.5}
{'Darey': 0, 'Itua': 800.0, 'Dayo': 2490.0}

line 39  if data[name] <= 5000:
    ^
IndentationError: unexpected indent
0 Sten Terje Falnes · September 10, 2016
HI, i tried the code in Pycharm. It ran just fine after I corrected some indentation of the different lines.

Hope that helps.
  • 1

Python

130,896 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator