Home > Blockchain >  How do I use if statement or for loop for this project?
How do I use if statement or for loop for this project?

Time:01-25

I'm making a project that prints out the outcome for this: Denmark: first 1000 Euro no tax, 10% on the second 1000 (in addition to it), 20% on the third 1000 (in addition to it), and so on...

If the input is: 6100 then:

Denmark:

0.0 * 1000   0.1 * 1000   0.2 * 1000   0.3 * 1000   0.4 * 1000   0.5 * 1000   0.6 * 100 = 1560.0

How can I make this happen with a if statement or a for loop?

I tried using this, but I saw that this wouldn't work.

income = int(input('Income: '))

percent_counter = 0
income_counter = 0

if income > 1000:
    no_tax = 0.0 * 1000
    percent_counter  = 0.1
    income_counter  = 1000 
else:
    no_tax = 0.0 * income

CodePudding user response:

You can try by doing :

income = int(input('Income: '))
tax = 0
percent = 0

for i in range(int(income/1000)):
    tax  = percent * 1000
    percent  = 0.1
tax  = percent * (income00)

print("Tax:", tax)

CodePudding user response:

You can do it using list comprehension:

income = int(input("Income: "))
percents = [i/10 for i in range(income//1000)]
tax = sum(percents)*1000
tax  = (percents[-1] 0.1)*(income00)
print(tax)
  • Related