我该如何去做一个范围70000以上的for-loop?我正在做一个所得税的for-loop,当收入超过70000时,有30%的税。我会做一些像for income in range(income-70000)
?所得税计算蟒蛇
那么,起初我开发了一个代码,没有使用循环,它工作得很好,但后来我被告知我需要在我的代码中加入一个循环。这就是我所拥有的,但对我来说使用for循环没有任何意义。有人能帮我吗?
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)
好了,现在我已经尝试使用while循环,但它并没有返回值。告诉我你的想法。我需要根据收入来计算所得税。第一万美元没有税。接下来的20000有10%。接下来的40000有20%。 70000以上是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
你能解释一下你在做什么吗?你在建立税表吗? for循环内发生了什么?之前/之后会发生什么? – selllikesybok
所得税?你需要什么循环?乘。 – shx2
为什么不只是'如果收入> = 7000'?这听起来像是你试图将英文指令“7000以上的收入,征收30%的税”转化为Python,但实际上“确实”会给你带来什么惊喜。 – Kevin