How do I go about making a for-loop with a range 70000 and above? I'm doing a for-loop for an income tax and when income is above 70000 there is a tax of 30%. Would i do something like for income in range(income-70000)
?
Well, at first i developed a code that didn't use a loop and it worked just fine, but then i was notified that i needed to incorporate a loop in my code. This is what i have, but it just doesn't make sense for me to use a for loop. Can someone help me?
def tax(income):
for income in range(10001):
tax = 0
for income in range(10002,30001):
tax = income*(0.1) + tax
for income in range(30002,70001):
tax = income*(0.2) + tax
for income in range(70002,100000):
tax = income*(0.3) + tax
print (tax)
Okay, so I have now tried with a while loop, but it doesn't return a value. Tell me what you think. I need to calculate the income tax based on an income. first 10000 dollars there is no tax. next 20000 there is 10%. Next 40000 there is 20%. and above 70000 is 30%.
def taxes(income):
income >= 0
while True:
if income < 10000:
tax = 0
elif income > 10000 and income <= 30000:
tax = (income-10000)*(0.1)
elif income > 30000 and income <= 70000:
tax = (income-30000)*(0.2) + 2000
elif income > 70000:
tax = (income - 70000)*(0.3) + 10000
return tax
if income >= 7000
? It sounds like you're trying to literally translate the English instruction "for incomes above 7000, levy a 30% tax" into Python, but whatfor
actually does may surprise you. – Intercessionwhile True:
loop, so when it finishes calculating the user's income tax, it starts over from the beginning again" – Intercessionwhile
wouldn't be in thetaxes
function, it would go around whatever is callingtaxes
. See this pastebin for a simple example. – IntercessionValueError: invalid literal for int() with base 10:
. It is having a problem withincome = int(raw_input('Enter your income: '))
. – Ushijima